/** * @TODO - is there a way we can target them directly instead of iterating through all? * * @param type $h * @param type $t * @param type $r * @param type $p * @return type */ function weekly_cron($h, $t, $r, $p) { $ia = elgg_set_ignore_access(true); // check for abandoned acls $dbprefix = elgg_get_config('dbprefix'); // try to make this as light as possible $options = array('type' => 'object', 'subtype' => 'granular_access', 'limit' => false); $batch = new ElggBatch('elgg_get_entities', $options); foreach ($batch as $b) { $sql = "SELECT COUNT(guid) as total FROM {$dbprefix}entities WHERE access_id = {$b->acl_id}"; $result = get_data($sql); if ($result[0]->total) { continue; } $sql = "SELECT COUNT(id) as total FROM {$dbprefix}metadata WHERE access_id = {$b->acl_id}"; $result = get_data($sql); if ($result[0]->total) { continue; } $sql = "SELECT COUNT(id) as total FROM {$dbprefix}annotations WHERE access_id = {$b->acl_id}"; $result = get_data($sql); if ($result[0]->total) { continue; } // this appears to be orphaned delete_access_collection($b->acl_id); $b->delete(); } elgg_set_ignore_access($ia); return $r; }
public function delete() { if ($acl = $this->getACL()) { delete_access_collection($acl); } if ($this->icontime) { $this->removeIcon(); } return parent::delete(); }
/** * Groups deleted, so remove access lists. */ function groups_delete_event_listener($event, $object_type, $object) { delete_access_collection($object->group_acl); return true; }
namespace hypeJunction\Faker; use ElggBatch; set_time_limit(0); $rels = $collections = 0; $max = (int) get_input('max', 20); $friends_count = rand(1, $max); $users = new ElggBatch('elgg_get_entities_from_metadata', array('types' => 'user', 'metadata_names' => '__faker', 'limit' => 0)); $dbprefix = elgg_get_config('dbprefix'); foreach ($users as $user) { remove_entity_relationships($user->guid, 'friend'); $query = "SELECT ag.id FROM {$dbprefix}access_collections ag WHERE ag.owner_guid = {$user->guid}"; $acls = get_data($query); foreach ($acls as $col) { delete_access_collection($col->id); } $friends = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => $friends_count, 'order_by' => 'RAND()', 'wheres' => array("e.guid != {$user->guid}"), 'metadata_names' => '__faker')); $rand_friends = false; $collection_id = create_access_collection('Best Fake Friends Collection', $user->guid); if ($collection_id) { $rand_friends = array_rand($friends, rand(2, $friends_count)); $collections++; } foreach ($friends as $friends_key => $friend) { if ($user->addFriend($friend->guid)) { $rels++; elgg_create_river_item(array('view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $user->guid, 'object_guid' => $friend->guid)); if ($rand_friends && array_key_exists($friends_key, $rand_friends)) { add_user_to_access_collection($friend->guid, $collection_id); }
<?php /** * Elgg friends: delete collection action * * @package Elgg.Core * @subpackage Friends.Collections */ $collection_id = (int) get_input('collection'); // check the ACL exists and we can edit if (!can_edit_access_collection($collection_id)) { register_error(elgg_echo("friends:collectiondeletefailed")); forward(REFERER); } if (delete_access_collection($collection_id)) { system_message(elgg_echo("friends:collectiondeleted")); } else { register_error(elgg_echo("friends:collectiondeletefailed")); } forward(REFERER);
public function testCanEditACLHook() { // if only we supported closures! global $acl_test_info; $acl_id = create_access_collection('test acl'); $acl_test_info = array('acl_id' => $acl_id, 'user' => $this->user); function test_acl_access_hook($hook, $type, $value, $params) { global $acl_test_info; if ($params['user_id'] == $acl_test_info['user']->guid) { $acl = get_access_collection($acl_test_info['acl_id']); $value[$acl->id] = $acl->name; } return $value; } elgg_register_plugin_hook_handler('access:collections:write', 'all', 'test_acl_access_hook'); // enable security since we usually run as admin $ia = elgg_set_ignore_access(false); $result = can_edit_access_collection($acl_id, $this->user->guid); $this->assertTrue($result); $ia = elgg_set_ignore_access($ia); elgg_unregister_plugin_hook_handler('access:collections:write', 'all', 'test_acl_access_hook'); delete_access_collection($acl_id); }
* @package Elgg * @subpackage Core * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author Curverider Ltd * @copyright Curverider Ltd 2008-2009 * @link http://elgg.org/ */ // Make sure we're logged in (send us to the front page if not) gatekeeper(); // Get input data $collection_id = (int) get_input('collection'); // Check to see that the access collection exist and grab its owner $get_collection = get_access_collection($collection_id); if ($get_collection) { if ($get_collection->owner_guid == $_SESSION['user']->getGUID()) { $delete_collection = delete_access_collection($collection_id); // Success message if ($delete_collection) { system_message(elgg_echo("friends:collectiondeleted")); } else { register_error(elgg_echo("friends:collectiondeletefailed")); } } else { // Failure message register_error(elgg_echo("friends:collectiondeletefailed")); } } else { // Failure message register_error(elgg_echo("friends:collectiondeletefailed")); } // Forward to the collections page
public function testAddMemberToACLRemoveMember() { // create a new user to check against $user = new \ElggUser(); $user->username = '******'; $user->save(); $acl_id = create_access_collection('test acl'); $result = add_user_to_access_collection($user->guid, $acl_id); $this->assertTrue($result); if ($result) { $this->assertTrue($user->delete()); // since there are no more members this should return false $acl_members = get_members_of_access_collection($acl_id, true); $this->assertFalse($acl_members); } delete_access_collection($acl_id); }
/** * sort out acls when groups get deleted * @return boolean */ function process_group_deletion() { $deletions = elgg_get_config('granular_access_deletions'); if (!is_array($deletions)) { return true; } $guids = array_keys($deletions); // note these guids don't exist anymore $options = array('type' => 'object', 'subtype' => 'granular_access', 'metadata_name_value_pairs' => array('name' => 'access_list', 'value' => $guids), 'limit' => false); $batch = new ElggBatch('elgg_get_entities_from_metadata', $options); $ia = elgg_set_ignore_access(true); foreach ($batch as $granular_access) { if ($granular_access->single_group) { $granular_access->delete(); continue; } $access_list = (array) $granular_access->access_list; // remove any of the guids from the access_list $access_list = array_diff($access_list, $guids); if (!$access_list) { // the access list is empty no need for this access delete_access_collection($granular_access->acl_id); $granular_access->delete(); continue; } // make sure this doesn't just become a duplicate $token = get_token_from_guids($access_list); $entities = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'granular_access', 'metadata_name_value_pairs' => array('name' => 'token', 'value' => $token), 'wheres' => array("e.guid != {$granular_access->guid}"))); if ($entities) { if (merge_access($granular_access, $entities[0])) { delete_access_collection($granular_access->acl_id); $granular_access->delete(); continue; } } $granular_access->access_list = $access_list; repopulate_access_collection($granular_access); } elgg_set_config('granular_access_deletions', array()); elgg_set_ignore_access($ia); }
/** * handles the extended garbage collection * * @param string $hook hookname * @param string $type hooktype * @param mixed $returnvalue current return value * @param mixed $params original parameters * * @return void */ public static function collect($hook, $type, $returnvalue, $params) { if (elgg_get_plugin_setting('enable_gc', 'garbagecollector_extended') !== 'yes') { return; } elgg_register_plugin_hook_handler('permissions_check', 'all', '\\Elgg\\Values::getTrue'); $dbprefix = elgg_get_config('dbprefix'); // overrule access settigns $ia = elgg_get_ignore_access(); elgg_set_ignore_access(true); // cleanup entities if ($entity_guids = garbagecollector_extended_get_orphaned_entities()) { echo elgg_echo('garbagecollector_extended:cleanup', ['entities']); foreach ($entity_guids as $guid) { $entity = get_entity($guid); if ($entity) { $entity->delete(); } } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup access collections if ($acl_ids = garbagecollector_extended_get_orphaned_access_collections()) { echo elgg_echo('garbagecollector_extended:cleanup', ['access collections']); foreach ($acl_ids as $id) { delete_access_collection($id); } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup annotations if ($anno_ids = garbagecollector_extended_get_orphaned_annotations()) { echo elgg_echo('garbagecollector_extended:cleanup', ['annotations']); foreach ($anno_ids as $id) { elgg_delete_annotation_by_id($id); } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup metadata if ($meta_ids = garbagecollector_extended_get_orphaned_metadata()) { echo elgg_echo('garbagecollector_extended:cleanup', ['metadata']); foreach ($meta_ids as $id) { // We need to manualy delete metadata as the Elgg functions don't work because this is orphaned metadata // also we need to delete this one by one because of potential long query strings $sql = 'DELETE FROM ' . $dbprefix . 'metadata'; $sql .= ' WHERE id = ' . $id; delete_data($sql); } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup private settings if ($private_ids = garbagecollector_extended_get_orphaned_private_settings()) { echo elgg_echo('garbagecollector_extended:cleanup', ['private settings']); foreach ($private_ids as $id) { // We need to manualy delete private settings as Elgg doesn't have a function fot this // also we need to delete this one by one because of potential long query strings $sql = 'DELETE FROM ' . $dbprefix . 'private_settings'; $sql .= ' WHERE id = ' . $id; delete_data($sql); } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup relationships if ($rel_ids = garbagecollector_extended_get_orphaned_relationships()) { echo elgg_echo('garbagecollector_extended:cleanup', ['relationships']); foreach ($rel_ids as $id) { delete_relationship($id); } echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // cleanup river if ($river_ids = garbagecollector_extended_get_orphaned_river()) { echo elgg_echo('garbagecollector_extended:cleanup', ['river items']); elgg_delete_river(['ids' => $river_ids]); echo elgg_echo('garbagecollector_extended:done') . '\\n'; } // because we cleaned up a lot, do metastrings again garbagecollector_orphaned_metastrings(); // restore access settings elgg_set_ignore_access($ia); elgg_unregister_plugin_hook_handler('permissions_check', 'all', '\\Elgg\\Values::getTrue'); }
public function testCanEditACL() { $acl_id = create_access_collection('test acl', $this->user->guid); // should be true since it's the owner $result = can_edit_access_collection($acl_id, $this->user->guid); $this->assertTrue($result); // should be true since IA is on. $ia = elgg_set_ignore_access(true); $result = can_edit_access_collection($acl_id); $this->assertTrue($result); elgg_set_ignore_access($ia); // should be false since IA is off $ia = elgg_set_ignore_access(false); $result = can_edit_access_collection($acl_id); $this->assertFalse($result); elgg_set_ignore_access($ia); delete_access_collection($acl_id); }