Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+73 -40
View File
@@ -2,9 +2,9 @@
/**
* @brief Active Record Pattern
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 18 Feb 2013
* @version SVN_VERSION_NUMBER
*/
@@ -41,6 +41,7 @@ abstract class _ActiveRecord
/**
* @brief [ActiveRecord] Database ID Fields
* @note If using this, declare a static $multitonMap = array(); in the child class to prevent duplicate loading queries
*/
protected static $databaseIdFields = array();
@@ -54,7 +55,7 @@ abstract class _ActiveRecord
* @note This needs to be declared in any child classes as well, only declaring here for editor code-complete/error-check functionality
*/
protected static $multitons = array();
/**
* @brief [ActiveRecord] Database Connection
*/
@@ -69,7 +70,7 @@ abstract class _ActiveRecord
* @see \IPS\Db::build
* @param int|string $id ID
* @param string $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details)
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details) - if used will cause multiton store to be skipped and a query always ran
* @return static
* @throws \InvalidArgumentException
* @throws \OutOfRangeException
@@ -89,33 +90,49 @@ abstract class _ActiveRecord
}
/* Does that exist in the multiton store? */
if( $idField === static::$databasePrefix . static::$databaseColumnId and !empty( static::$multitons[ $id ] ) )
if ( !$extraWhereClause )
{
return static::$multitons[ $id ];
if( $idField === static::$databasePrefix . static::$databaseColumnId )
{
if ( !empty( static::$multitons[ $id ] ) )
{
return static::$multitons[ $id ];
}
}
elseif ( isset( static::$multitonMap ) and isset( static::$multitonMap[ $idField ][ $id ] ) )
{
return static::$multitons[ static::$multitonMap[ $idField ][ $id ] ];
}
}
/* If not, find it */
else
/* Load it */
try
{
/* Load it */
try
{
$row = static::constructLoadQuery( $id, $idField, $extraWhereClause )->first();
}
catch ( \UnderflowException $e )
{
throw new \OutOfRangeException;
}
/* If it doesn't exist in the multiton store, set it */
if( !isset( static::$multitons[ $row[ static::$databasePrefix . static::$databaseColumnId ] ] ) )
{
static::$multitons[ $row[ static::$databasePrefix . static::$databaseColumnId ] ] = static::constructFromData( $row );
}
/* And return it */
return static::$multitons[ $row[ static::$databasePrefix . static::$databaseColumnId ] ];
$row = static::constructLoadQuery( $id, $idField, $extraWhereClause )->first();
}
catch ( \UnderflowException $e )
{
throw new \OutOfRangeException;
}
/* If it doesn't exist in the multiton store, set it */
if( !isset( static::$multitons[ $row[ static::$databasePrefix . static::$databaseColumnId ] ] ) )
{
static::$multitons[ $row[ static::$databasePrefix . static::$databaseColumnId ] ] = static::constructFromData( $row );
}
if ( isset( static::$multitonMap ) )
{
foreach ( static::$databaseIdFields as $field )
{
if ( $row[ $field ] )
{
static::$multitonMap[ $field ][ $row[ $field ] ] = $row[ static::$databasePrefix . static::$databaseColumnId ];
}
}
}
/* And return it */
return static::$multitons[ $row[ static::$databasePrefix . static::$databaseColumnId ] ];
}
/**
@@ -127,12 +144,14 @@ abstract class _ActiveRecord
* @throws \OutOfRangeException
*/
public static function loadFromUrl( \IPS\Http\Url $url )
{
$qs = array_merge( $url->queryString, $url->getFriendlyUrlData() );
if ( isset( $qs['id'] ) )
{
if ( isset( $url->queryString['id'] ) )
{
return static::load( $qs['id'] );
return static::load( $url->queryString['id'] );
}
if ( isset( $url->hiddenQueryString['id'] ) )
{
return static::load( $url->hiddenQueryString['id'] );
}
throw new \InvalidArgumentException;
@@ -197,11 +216,12 @@ abstract class _ActiveRecord
}
/* Import data */
$databasePrefixLength = \strlen( static::$databasePrefix );
foreach ( $data as $k => $v )
{
if( static::$databasePrefix AND mb_strpos( $k, static::$databasePrefix ) === 0 )
{
$k = \substr( $k, \strlen( static::$databasePrefix ) );
$k = \substr( $k, $databasePrefixLength );
}
$obj->_data[ $k ] = $v;
@@ -284,7 +304,8 @@ abstract class _ActiveRecord
{
if( method_exists( $this, 'get_'.$key ) )
{
return call_user_func( array( $this, 'get_'.$key ) );
$method = 'get_' . $key;
return $this->$method();
}
elseif( isset( $this->_data[ $key ] ) or isset( static::$bitOptions[ $key ] ) )
{
@@ -320,11 +341,12 @@ abstract class _ActiveRecord
{
$oldValues = $this->_data;
call_user_func( array( $this, 'set_'.$key ), $value );
$method = 'set_' . $key;
$this->$method( $value );
foreach( $this->_data as $k => $v )
{
if( !array_key_exists( $k, $oldValues ) or ( $v instanceof \IPS\Patterns\Bitwise and !( $oldValues[ $k ] instanceof \IPS\Patterns\Bitwise ) ) or $oldValues[ $k ] != $v )
if( !array_key_exists( $k, $oldValues ) or ( $v instanceof \IPS\Patterns\Bitwise and !( $oldValues[ $k ] instanceof \IPS\Patterns\Bitwise ) ) or $oldValues[ $k ] !== $v )
{
$this->changed[ $k ] = $v;
}
@@ -334,7 +356,7 @@ abstract class _ActiveRecord
}
else
{
if ( !array_key_exists( $key, $this->_data ) or $this->_data[ $key ] != $value )
if ( !array_key_exists( $key, $this->_data ) or $this->_data[ $key ] !== $value )
{
$this->changed[ $key ] = $value;
}
@@ -351,7 +373,18 @@ abstract class _ActiveRecord
*/
public function __isset( $key )
{
return isset( $this->_data[ $key ] );
if ( method_exists( $this, 'get_' . $key ) )
{
$method = 'get_' . $key;
return $this->$method() !== NULL;
}
if ( isset( $this->_data[$key] ) )
{
return TRUE;
}
return FALSE;
}
/**
@@ -393,7 +426,7 @@ abstract class _ActiveRecord
{
$data = $this->changed;
}
foreach ( array_keys( static::$bitOptions ) as $k )
{
if ( $this->$k instanceof Bitwise )
@@ -485,11 +518,11 @@ abstract class _ActiveRecord
* @param \IPS\DateTime|int|NULL $date Only users who started following before this date will be returned. NULL for no restriction
* @param int|array $limit LIMIT clause
* @param string $order Column to order by
* @param int $flags Flags to pass to select (e.g. \IPS\DB::SELECT_SQL_CALC_FOUND_ROWS)
* @param int $flags Flags to pass to select (e.g. \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS)
* @return \IPS\Db\Select
* @throws |\BadMethodCallException
*/
protected static function _followers( $area, $id, $privacy, $frequencyTypes, $date, $limit, $order=NULL, $flags=\IPS\DB::SELECT_SQL_CALC_FOUND_ROWS )
protected static function _followers( $area, $id, $privacy, $frequencyTypes, $date, $limit, $order=NULL, $flags=\IPS\Db::SELECT_SQL_CALC_FOUND_ROWS )
{
/* Initial where clause */
$where[] = array( 'follow_app=? AND follow_area=? AND follow_rel_id=?', static::$application, $area, $id );