Skip to content

Commit

Permalink
Merge branch '1.8' - after start.php reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
cash committed Feb 1, 2012
2 parents 645de88 + e7b2f4f commit 279f007
Show file tree
Hide file tree
Showing 102 changed files with 843 additions and 511 deletions.
2 changes: 1 addition & 1 deletion actions/admin/plugins/activate.php
Expand Up @@ -38,7 +38,7 @@
// don't regenerate the simplecache because the plugin won't be // don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regenerate as needed // loaded until next run. Just invalidate and let it regenerate as needed
elgg_invalidate_simplecache(); elgg_invalidate_simplecache();
elgg_filepath_cache_reset(); elgg_reset_system_cache();


if (count($activated_guids) === 1) { if (count($activated_guids) === 1) {
$url = 'admin/plugins'; $url = 'admin/plugins';
Expand Down
2 changes: 1 addition & 1 deletion actions/admin/plugins/activate_all.php
Expand Up @@ -28,6 +28,6 @@
// don't regenerate the simplecache because the plugin won't be // don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed // loaded until next run. Just invalidate and let it regnerate as needed
elgg_invalidate_simplecache(); elgg_invalidate_simplecache();
elgg_filepath_cache_reset(); elgg_reset_system_cache();


forward(REFERER); forward(REFERER);
2 changes: 1 addition & 1 deletion actions/admin/plugins/deactivate.php
Expand Up @@ -37,7 +37,7 @@
// don't regenerate the simplecache because the plugin won't be // don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed // loaded until next run. Just invalidate and let it regnerate as needed
elgg_invalidate_simplecache(); elgg_invalidate_simplecache();
elgg_filepath_cache_reset(); elgg_reset_system_cache();


if (count($plugin_guids) == 1) { if (count($plugin_guids) == 1) {
$url = 'admin/plugins'; $url = 'admin/plugins';
Expand Down
2 changes: 1 addition & 1 deletion actions/admin/plugins/deactivate_all.php
Expand Up @@ -28,6 +28,6 @@
// don't regenerate the simplecache because the plugin won't be // don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed // loaded until next run. Just invalidate and let it regnerate as needed
elgg_invalidate_simplecache(); elgg_invalidate_simplecache();
elgg_filepath_cache_reset(); elgg_reset_system_cache();


forward(REFERER); forward(REFERER);
2 changes: 1 addition & 1 deletion actions/admin/plugins/set_priority.php
Expand Up @@ -34,6 +34,6 @@
// don't regenerate the simplecache because the plugin won't be // don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed // loaded until next run. Just invalidate and let it regnerate as needed
elgg_invalidate_simplecache(); elgg_invalidate_simplecache();
elgg_filepath_cache_reset(); elgg_reset_system_cache();


forward(REFERER); forward(REFERER);
2 changes: 1 addition & 1 deletion actions/admin/site/flush_cache.php
Expand Up @@ -4,7 +4,7 @@
*/ */


elgg_invalidate_simplecache(); elgg_invalidate_simplecache();
elgg_filepath_cache_reset(); elgg_reset_system_cache();


system_message(elgg_echo('admin:cache:flushed')); system_message(elgg_echo('admin:cache:flushed'));
forward(REFERER); forward(REFERER);
9 changes: 4 additions & 5 deletions actions/admin/site/update_advanced.php
Expand Up @@ -9,8 +9,7 @@
* @subpackage Administration.Site * @subpackage Administration.Site
*/ */


if (datalist_get('default_site')) { if ($site = elgg_get_site_entity()) {
$site = get_entity(datalist_get('default_site'));
if (!($site instanceof ElggSite)) { if (!($site instanceof ElggSite)) {
throw new InstallationException(elgg_echo('InvalidParameterException:NonElggSite')); throw new InstallationException(elgg_echo('InvalidParameterException:NonElggSite'));
} }
Expand All @@ -26,10 +25,10 @@
elgg_disable_simplecache(); elgg_disable_simplecache();
} }


if (get_input('viewpath_cache_enabled')) { if (get_input('system_cache_enabled')) {
elgg_enable_filepath_cache(); elgg_enable_system_cache();
} else { } else {
elgg_disable_filepath_cache(); elgg_disable_system_cache();
} }


set_config('default_access', get_input('default_access', ACCESS_PRIVATE), $site->getGUID()); set_config('default_access', get_input('default_access', ACCESS_PRIVATE), $site->getGUID());
Expand Down
3 changes: 1 addition & 2 deletions actions/admin/site/update_basic.php
Expand Up @@ -10,8 +10,7 @@
* @subpackage Administration.Site * @subpackage Administration.Site
*/ */


if (datalist_get('default_site')) { if ($site = elgg_get_site_entity()) {
$site = get_entity(datalist_get('default_site'));
if (!($site instanceof ElggSite)) { if (!($site instanceof ElggSite)) {
throw new InstallationException(elgg_echo('InvalidParameterException:NonElggSite')); throw new InstallationException(elgg_echo('InvalidParameterException:NonElggSite'));
} }
Expand Down
2 changes: 1 addition & 1 deletion actions/avatar/crop.php
Expand Up @@ -46,7 +46,7 @@
$file->delete(); $file->delete();
} }


system_message(elgg_echo('avatar:resize:fail')); register_error(elgg_echo('avatar:resize:fail'));
forward(REFERER); forward(REFERER);
} }
} }
Expand Down
1 change: 0 additions & 1 deletion actions/profile/fields/add.php
Expand Up @@ -2,7 +2,6 @@
/** /**
* Elgg profile plugin edit default profile action * Elgg profile plugin edit default profile action
* *
* @package ElggProfile
*/ */


$label = get_input('label'); $label = get_input('label');
Expand Down
1 change: 0 additions & 1 deletion actions/profile/fields/delete.php
Expand Up @@ -2,7 +2,6 @@
/** /**
* Elgg profile plugin edit default profile action removal * Elgg profile plugin edit default profile action removal
* *
* @package ElggProfile
*/ */


$id = get_input('id'); $id = get_input('id');
Expand Down
4 changes: 2 additions & 2 deletions actions/profile/fields/reorder.php
Expand Up @@ -2,11 +2,11 @@
/** /**
* Elgg profile plugin reorder fields * Elgg profile plugin reorder fields
* *
* @package ElggProfile
*/ */


$ordering = get_input('fieldorder'); $ordering = get_input('fieldorder');


$result = elgg_save_config('profile_custom_fields', $ordering); $result = elgg_save_config('profile_custom_fields', $ordering);


exit; // called by ajax so we exit
exit;
6 changes: 3 additions & 3 deletions documentation/info/config.php
Expand Up @@ -218,11 +218,11 @@
$CONFIG->simplecache_enabled; $CONFIG->simplecache_enabled;


/** /**
* Is view paths cache enabled * Is the system cache enabled
* *
* @global string $CONFIG->viewpath_cache_enabled * @global string $CONFIG->system_cache_enabled
*/ */
$CONFIG->viewpath_cache_enabled; $CONFIG->system_cache_enabled;


/** /**
* The site description from the current site object. * The site description from the current site object.
Expand Down
75 changes: 54 additions & 21 deletions engine/classes/ElggBatch.php
Expand Up @@ -3,47 +3,51 @@
* Efficiently run operations on batches of results for any function * Efficiently run operations on batches of results for any function
* that supports an options array. * that supports an options array.
* *
* This is usually used with elgg_get_entities() and friends, elgg_get_annotations() * This is usually used with elgg_get_entities() and friends,
* and elgg_get_metadata(). * elgg_get_annotations(), and elgg_get_metadata().
* *
* If you pass a valid PHP callback, all results will be run through that callback. * If you pass a valid PHP callback, all results will be run through that
* You can still foreach() through the result set after. Valid PHP callbacks * callback. You can still foreach() through the result set after. Valid
* can be a string, an array, or a closure. * PHP callbacks can be a string, an array, or a closure.
* {@link http://php.net/manual/en/language.pseudo-types.php} * {@link http://php.net/manual/en/language.pseudo-types.php}
* *
* The callback function must accept 3 arguments: an entity, the getter used, and the options used. * The callback function must accept 3 arguments: an entity, the getter
* used, and the options used.
* *
* Results from the callback are stored in callbackResult. * Results from the callback are stored in callbackResult. If the callback
* If the callback returns only booleans, callbackResults will be the combined * returns only booleans, callbackResults will be the combined result of
* result of all calls. * all calls.
* *
* If the callback returns anything else, callbackresult will be an indexed array * If the callback returns anything else, callbackresult will be an indexed
* of whatever the callback returns. If returning error handling information, * array of whatever the callback returns. If returning error handling
* you should include enough information to determine which result you're referring * information, you should include enough information to determine which
* to. * result you're referring to.
* *
* Don't combine returning bools and returning something else. * Don't combine returning bools and returning something else.
* *
* Note that returning false will not stop the foreach. * Note that returning false will not stop the foreach.
* *
* @warning If your callback or foreach loop deletes or disable entities
* you MUST call setIncrementOffset(false) or set that when instantiating.
* This forces the offset to stay what it was in the $options array.
*
* @example * @example
* <code> * <code>
* // using foreach
* $batch = new ElggBatch('elgg_get_entities', array()); * $batch = new ElggBatch('elgg_get_entities', array());
* $batch->setIncrementOffset(false);
* *
* foreach ($batch as $entity) { * foreach ($batch as $entity) {
* $entity->disable(); * $entity->disable();
* } * }
* *
* // using both a callback
* $callback = function($result, $getter, $options) { * $callback = function($result, $getter, $options) {
* var_dump("Going to delete annotation id: $result->id"); * var_dump("Looking at annotation id: $result->id");
* return true; * return true;
* } * }
* *
* $batch = new ElggBatch('elgg_get_annotations', array('guid' => 2), $callback); * $batch = new ElggBatch('elgg_get_annotations', array('guid' => 2), $callback);
*
* foreach ($batch as $annotation) {
* $annotation->delete();
* }
* </code> * </code>
* *
* @package Elgg.Core * @package Elgg.Core
Expand Down Expand Up @@ -138,6 +142,13 @@ class ElggBatch
*/ */
public $callbackResult = null; public $callbackResult = null;


/**
* If false, offset will not be incremented. This is used for callbacks/loops that delete.
*
* @var bool
*/
private $incrementOffset = true;

/** /**
* Batches operations on any elgg_get_*() or compatible function that supports * Batches operations on any elgg_get_*() or compatible function that supports
* an options array. * an options array.
Expand All @@ -156,12 +167,18 @@ class ElggBatch
* @param int $chunk_size The number of entities to pull in before requesting more. * @param int $chunk_size The number of entities to pull in before requesting more.
* You have to balance this between running out of memory in PHP * You have to balance this between running out of memory in PHP
* and hitting the db server too often. * and hitting the db server too often.
* @param bool $inc_offset Increment the offset on each fetch. This must be false for
* callbacks that delete rows. You can set this after the
* object is created with {@see ElggBatch::setIncrementOffset()}.
*/ */
public function __construct($getter, $options, $callback = null, $chunk_size = 25) { public function __construct($getter, $options, $callback = null, $chunk_size = 25,
$inc_offset = true) {

$this->getter = $getter; $this->getter = $getter;
$this->options = $options; $this->options = $options;
$this->callback = $callback; $this->callback = $callback;
$this->chunkSize = $chunk_size; $this->chunkSize = $chunk_size;
$this->setIncrementOffset($inc_offset);


if ($this->chunkSize <= 0) { if ($this->chunkSize <= 0) {
$this->chunkSize = 25; $this->chunkSize = 25;
Expand All @@ -174,7 +191,7 @@ public function __construct($getter, $options, $callback = null, $chunk_size = 2
// if passed a callback, create a new ElggBatch with the same options // if passed a callback, create a new ElggBatch with the same options
// and pass each to the callback. // and pass each to the callback.
if ($callback && is_callable($callback)) { if ($callback && is_callable($callback)) {
$batch = new ElggBatch($getter, $options, null, $chunk_size); $batch = new ElggBatch($getter, $options, null, $chunk_size, $inc_offset);


$all_results = null; $all_results = null;


Expand Down Expand Up @@ -245,9 +262,15 @@ private function getNextResultsChunk() {
} }
} }


if ($this->incrementOffset) {
$offset = $this->offset + $this->retrievedResults;
} else {
$offset = $this->offset;
}

$current_options = array( $current_options = array(
'limit' => $limit, 'limit' => $limit,
'offset' => $this->offset + $this->retrievedResults 'offset' => $offset
); );


$options = array_merge($this->options, $current_options); $options = array_merge($this->options, $current_options);
Expand All @@ -269,6 +292,16 @@ private function getNextResultsChunk() {
} }
} }


/**
* Increment the offset from the original options array? Setting to
* false is required for callbacks that delete rows.
*
* @param bool $increment
*/
public function setIncrementOffset($increment = true) {
$this->incrementOffset = (bool) $increment;
}

/** /**
* Implements Iterator * Implements Iterator
*/ */
Expand Down
10 changes: 8 additions & 2 deletions engine/classes/ElggUser.php
Expand Up @@ -384,7 +384,6 @@ function listFriends($subtype = "", $limit = 10, array $vars = array()) {
'relationship' => 'friend', 'relationship' => 'friend',
'relationship_guid' => $this->guid, 'relationship_guid' => $this->guid,
'limit' => $limit, 'limit' => $limit,
'offset' => get_input('offset', 0),
'full_view' => false, 'full_view' => false,
); );


Expand Down Expand Up @@ -458,7 +457,14 @@ function listGroups($subtype = "", $limit = 10, $offset = 0) {
* @return array|false * @return array|false
*/ */
public function getObjects($subtype = "", $limit = 10, $offset = 0) { public function getObjects($subtype = "", $limit = 10, $offset = 0) {
return get_user_objects($this->getGUID(), $subtype, $limit, $offset); $params = array(
'type' => 'object',
'subtype' => $subtype,
'owner_guid' => $this->getGUID(),
'limit' => $limit,
'offset' => $offset
);
return elgg_get_entities($params);
} }


/** /**
Expand Down
4 changes: 3 additions & 1 deletion engine/lib/access.php
Expand Up @@ -671,8 +671,10 @@ function add_user_to_access_collection($user_guid, $collection_id) {
return false; return false;
} }


// if someone tries to insert the same data twice, we do a no-op on duplicate key
$q = "INSERT INTO {$CONFIG->dbprefix}access_collection_membership $q = "INSERT INTO {$CONFIG->dbprefix}access_collection_membership
SET access_collection_id = {$collection_id}, user_guid = {$user_guid}"; SET access_collection_id = $collection_id, user_guid = $user_guid
ON DUPLICATE KEY UPDATE user_guid = user_guid";
$result = insert_data($q); $result = insert_data($q);


return $result !== false; return $result !== false;
Expand Down
4 changes: 3 additions & 1 deletion engine/lib/annotations.php
Expand Up @@ -209,9 +209,11 @@ function elgg_get_annotations(array $options = array()) {
* Deletes annotations based on $options. * Deletes annotations based on $options.
* *
* @warning Unlike elgg_get_annotations() this will not accept an empty options array! * @warning Unlike elgg_get_annotations() this will not accept an empty options array!
* This requires at least one constraint: annotation_owner_guid(s),
* annotation_name(s), annotation_value(s), or guid(s) must be set.
* *
* @param array $options An options array. {@See elgg_get_annotations()} * @param array $options An options array. {@See elgg_get_annotations()}
* @return mixed * @return mixed Null if the metadata name is invalid. Bool on success or fail.
* @since 1.8.0 * @since 1.8.0
*/ */
function elgg_delete_annotations(array $options) { function elgg_delete_annotations(array $options) {
Expand Down

0 comments on commit 279f007

Please sign in to comment.