setIncrementOffset() public method

Increment the offset from the original options array? Setting to false is required for callbacks that delete rows.
public setIncrementOffset ( boolean $increment = true ) : void
$increment boolean Set to false when deleting data
return void
コード例 #1
0
function tidypics_batch_delete_images()
{
    // delete
    $log = elgg_get_config('tidypics_log');
    $log_time = elgg_get_config('tidypics_logtime');
    $options = array('type' => 'object', 'subtype' => 'image', 'metadata_name_value_pairs' => array('name' => 'tidypics_delete_check', 'value' => $log_time), 'limit' => false);
    $images = new ElggBatch('elgg_get_entities_from_metadata', $options);
    $images->setIncrementOffset(false);
    $total = elgg_get_entities_from_metadata(array_merge($options, array('count' => true)));
    file_put_contents($log, "Starting deletion of {$total} images" . "\n", FILE_APPEND);
    $i = 0;
    $count = 0;
    foreach ($images as $image) {
        $count++;
        if ($image->delete()) {
            $i++;
        }
        if ($count == 1 || !($count % 25)) {
            $time = date('m/d/Y g:i:s a');
            $j = $count - $i;
            $message = "Deleted {$i}, skipped {$j}, of {$total} images as of {$time}";
            file_put_contents($log, $message . "\n", FILE_APPEND);
        }
    }
    $message = '<div class="done">Completed: Deleted ' . $i . ', skipped ' . $j . ', of ' . $total . '</div>';
    file_put_contents($log, $message . "\n", FILE_APPEND);
}
コード例 #2
0
ファイル: Folder.php プロジェクト: coldtrick/file_tools
 /**
  * Remove all the files in this folder
  *
  * @param \ElggObject $entity the folder to removed the file from
  *
  * @return void
  */
 protected static function removeFolderContents(\ElggObject $entity)
 {
     $batch = new \ElggBatch('elgg_get_entities_from_relationship', ['type' => 'object', 'subtype' => 'file', 'container_guid' => $entity->getContainerGUID(), 'limit' => false, 'relationship' => FILE_TOOLS_RELATIONSHIP, 'relationship_guid' => $entity->getGUID()]);
     $batch->setIncrementOffset(false);
     foreach ($batch as $file) {
         $file->delete();
     }
 }
コード例 #3
0
function import_to_stormpath()
{
    $dbprefix = elgg_get_config('dbprefix');
    $subject = elgg_get_plugin_setting('import_subject', PLUGIN_ID);
    $message = elgg_get_plugin_setting('import_message', PLUGIN_ID);
    $site = elgg_get_site_entity();
    $site_url = elgg_get_site_url();
    if (!$subject || !$message) {
        error_log('no subject/message');
        return true;
    }
    if (is_elgg18()) {
        $name_id = add_metastring('__stormpath_user');
        $value_id = add_metastring(1);
    } else {
        $name_id = elgg_get_metastring_id('__stormpath_user');
        $value_id = elgg_get_metastring_id(1);
    }
    $options = array('type' => 'user', 'joins' => array("LEFT JOIN {$dbprefix}metadata md ON md.entity_guid = e.guid AND md.name_id = {$name_id}"), 'wheres' => array('md.name_id IS NULL'), 'limit' => false);
    $batch = new \ElggBatch('elgg_get_entities', $options);
    $batch->setIncrementOffset(false);
    foreach ($batch as $user) {
        // search stormpath for a matching account
        $application = get_application();
        $accts = $application->getAccounts(array('email' => $user->email));
        $already_exists = false;
        foreach ($accts as $a) {
            $user->__stormpath_user = $a->href;
            error_log('set user ' . $user->username . ': ' . $a->href);
            $already_exists = true;
            break;
        }
        if ($already_exists) {
            continue;
        }
        // change it locally
        $password = generate_random_cleartext_password();
        $user->salt = _elgg_generate_password_salt();
        $user->password = generate_user_password($user, $password);
        $user->save();
        error_log('adding to stormpath ' . $user->email);
        $result = add_to_stormpath($user, $password);
        if ($result) {
            // notify them of the change
            // replace tokens in the message
            $message_m = str_replace('{{password}}', $password, $message);
            $message_m = str_replace('{{name}}', $user->name, $message_m);
            $message_m = str_replace('{{username}}', $user->username, $message_m);
            $message_m = str_replace('{{email}}', $user->email, $message_m);
            $message_m = str_replace('{{forgot_password}}', $site_url . 'forgotpassword', $message_m);
            $message_m = str_replace('{{site_email}}', $site->email, $message_m);
            $message_m = str_replace('{{site_url}}', $site_url, $message_m);
            notify_user($user->guid, $site->guid, $subject, $message_m, null, 'email');
        }
    }
}
コード例 #4
0
ファイル: Cache.php プロジェクト: coldtrick/widget_manager
 /**
  * Listen to the cache flush event to invalidate cache of widgets content
  *
  * @param string $event  the name of the event
  * @param string $type   the type of the event
  * @param mixed  $object supplied param
  *
  * @return void
  */
 public static function resetWidgetsCache($event, $type, $object)
 {
     $ia = elgg_set_ignore_access(true);
     $batch = new \ElggBatch('elgg_get_entities_from_private_settings', ['type' => 'object', 'subtype' => 'widget', 'limit' => false, 'private_setting_name' => 'widget_manager_cached_data']);
     $batch->setIncrementOffset(false);
     foreach ($batch as $entity) {
         $entity->removePrivateSetting('widget_manager_cached_data');
     }
     elgg_set_ignore_access($ia);
 }
コード例 #5
0
ファイル: upgrades.php プロジェクト: hypejunction/hypeinbox
/**
 * Migrates notifications to private messages
 */
function inbox_upgrade_20162209()
{
    $setting = elgg_get_plugin_setting('default_message_types', 'hypeInbox');
    if ($setting) {
        $setting = unserialize($setting);
        unset($setting['__notification']);
        elgg_set_plugin_setting('default_message_types', serialize($setting), 'hypeInbox');
    }
    $messages = new ElggBatch('elgg_get_entities_from_metadata', ['types' => 'object', 'subtypes' => 'messages', 'metadata_name_value_pairs' => ['name' => 'msgType', 'value' => '__notification'], 'limit' => 0]);
    $messages->setIncrementOffset(false);
    foreach ($messages as $message) {
        $message->msgType = hypeJunction\Inbox\Message::TYPE_PRIVATE;
    }
}
コード例 #6
0
 /**
  * Move the imported abstract fields to description
  *
  * @param string $event  the name of the event
  * @param string $type   the type of the event
  * @param mixed  $object supplied params
  *
  * @return void
  */
 public static function abstractToDescription($event, $type, $object)
 {
     $options = ['type' => 'object', 'subtype' => \Publication::SUBTYPE, 'limit' => false, 'metadata_name' => 'abstract'];
     $entities = new \ElggBatch('elgg_get_entities_from_metadata', $options);
     $entities->setIncrementOffset(false);
     foreach ($entities as $entity) {
         // append abstract to description
         $entity->description .= ' ' . $entity->abstract;
         // remove trailing spaces
         trim($entity->description);
         // unset abstract
         unset($entity->abstract);
         // save new data
         $entity->save();
     }
 }
コード例 #7
0
ファイル: Upgrade.php プロジェクト: coldtrick/static
 /**
  * Migrate old tree structure to new structure
  *
  * @param string $event  the name of the event
  * @param string $type   the type of the event
  * @param mixed  $entity supplied entity
  *
  * @return void
  */
 public static function migrateTreeStructure($event, $type, $entity)
 {
     // this process could take a while
     set_time_limit(0);
     // set entity options
     $options = ['type' => 'object', 'subtype' => \StaticPage::SUBTYPE, 'metadata_name' => 'parent_guid', 'site_guids' => false, 'limit' => false];
     // set default metadata options
     $metadata_options = ['metadata_name' => 'parent_guid', 'site_guids' => false, 'limit' => false];
     // make sure we can get all entities
     $ia = elgg_set_ignore_access(true);
     // create a batch for processing
     $batch = new \ElggBatch('elgg_get_entities_from_metadata', $options);
     $batch->setIncrementOffset(false);
     foreach ($batch as $entity) {
         $metadata_options['guid'] = $entity->getGUID();
         $parent_guid = (int) $entity->parent_guid;
         if (empty($parent_guid)) {
             // workaround for multi-site
             elgg_delete_metadata($metadata_options);
             continue;
         }
         $parent = get_entity($parent_guid);
         if (empty($parent)) {
             // workaround for multi-site
             elgg_delete_metadata($metadata_options);
             continue;
         }
         // set correct container
         $entity->container_guid = $parent->getGUID();
         $entity->save();
         // find the root page for the tree
         $root = self::findOldRootPage($entity);
         if (empty($root)) {
             // workaround for multi-site
             elgg_delete_metadata($metadata_options);
             continue;
         }
         // add relationship to the correct tree
         remove_entity_relationships($entity->getGUID(), 'subpage_of');
         $entity->addRelationship($root->getGUID(), 'subpage_of');
         // workaround for multi-site
         elgg_delete_metadata($metadata_options);
     }
     // restore access
     elgg_set_ignore_access($ia);
 }
コード例 #8
0
ファイル: Cron.php プロジェクト: coldtrick/csv_exporter
 /**
  * Cleanup the old exports
  *
  * @param string $hook         the name of the hook
  * @param string $type         the type of the hook
  * @param string $return_value current return value
  * @param array  $params       supplied params
  *
  * @return void
  */
 public static function cleanupExports($hook, $type, $return_value, $params)
 {
     $time = (int) elgg_extract('time', $params, time());
     $retention = (int) elgg_get_plugin_setting('retention', 'csv_exporter');
     if ($retention < 1) {
         // no cleanup
         return;
     }
     // prepare options
     $options = ['type' => 'object', 'subtype' => \CSVExport::SUBTYPE, 'limit' => false, 'metadata_name_value_pairs' => ['name' => 'completed', 'value' => strtotime("today -{$retention} days", $time), 'operand' => '<']];
     // ignore access
     $ia = elgg_set_ignore_access(true);
     $batch = new \ElggBatch('elgg_get_entities_from_metadata', $options);
     $batch->setIncrementOffset(false);
     /* @var $entity \CSVExport */
     foreach ($batch as $entity) {
         $entity->delete();
     }
     // restore access
     elgg_set_ignore_access($ia);
 }
コード例 #9
0
ファイル: ElggBatchTest.php プロジェクト: cyrixhero/Elgg
 public function testElggBatchIncOffset()
 {
     // normal increment
     $options = array('offset' => 0, 'limit' => 11);
     $batch = new \ElggBatch([\ElggBatchTest::class, 'elgg_batch_callback_test'], $options, null, 5);
     $j = 0;
     foreach ($batch as $e) {
         $offset = floor($j / 5) * 5;
         $this->assertEqual($offset, $e['offset']);
         $this->assertEqual($j + 1, $e['index']);
         $j++;
     }
     $this->assertEqual(11, $j);
     // no increment, 0 start
     \ElggBatchTest::elgg_batch_callback_test(array(), true);
     $options = array('offset' => 0, 'limit' => 11);
     $batch = new \ElggBatch([\ElggBatchTest::class, 'elgg_batch_callback_test'], $options, null, 5);
     $batch->setIncrementOffset(false);
     $j = 0;
     foreach ($batch as $e) {
         $this->assertEqual(0, $e['offset']);
         // should always be the same 5
         $this->assertEqual($e['index'], $j + 1 - floor($j / 5) * 5);
         $j++;
     }
     $this->assertEqual(11, $j);
     // no increment, 3 start
     \ElggBatchTest::elgg_batch_callback_test(array(), true);
     $options = array('offset' => 3, 'limit' => 11);
     $batch = new \ElggBatch([\ElggBatchTest::class, 'elgg_batch_callback_test'], $options, null, 5);
     $batch->setIncrementOffset(false);
     $j = 0;
     foreach ($batch as $e) {
         $this->assertEqual(3, $e['offset']);
         // same 5 results
         $this->assertEqual($e['index'], $j + 4 - floor($j / 5) * 5);
         $j++;
     }
     $this->assertEqual(11, $j);
 }
コード例 #10
0
ファイル: functions.php プロジェクト: pleio/subsite_manager
/**
 * Move an entity to a new site (can anly be call by subsite_manager_move_group_to_site())
 *
 * @param ElggEntity $entity            the entity to move
 * @param ElggSite   $target_site       the target site
 * @param array      $access_conversion array with group and site access levels
 *
 * @access private
 *
 * @return bool
 */
function subsite_manager_move_entity_to_site(ElggEntity $entity, ElggSite $target_site, array $access_conversion)
{
    static $newentity_cache;
    $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
    if (!isset($backtrace[1])) {
        return false;
    }
    $function = elgg_extract("function", $backtrace[1]);
    if (empty($function) || !in_array($function, array("subsite_manager_move_group_to_site", "subsite_manager_move_entity_to_site"))) {
        // because this is a dangerous function only allow it to be called the correct way
        return false;
    }
    if (empty($entity) || !$entity instanceof ElggEntity) {
        return false;
    }
    if (empty($target_site) || !elgg_instanceof($target_site, "site")) {
        return false;
    }
    if ($entity->site_guid == $target_site->getGUID()) {
        return false;
    }
    // check for access conversion rules
    if (empty($access_conversion) || !is_array($access_conversion)) {
        return false;
    }
    $group_acl = (int) elgg_extract("group_acl", $access_conversion);
    if (empty($group_acl)) {
        return false;
    }
    $old_site_acl = (int) elgg_extract("site_acl", $access_conversion);
    $affected_access = array(ACCESS_PUBLIC, ACCESS_LOGGED_IN);
    if (!empty($old_site_acl)) {
        $affected_access[] = $old_site_acl;
    }
    // ignore access and show hidden entities
    $ia = elgg_set_ignore_access(true);
    $hidden = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    // first move sub entities (eg blogs in group, event registrations, etc)
    $options = array("type" => "object", "container_guid" => $entity->getGUID(), "limit" => false);
    $batch = new ElggBatch("elgg_get_entities", $options);
    $batch->setIncrementOffset(false);
    foreach ($batch as $sub_entity) {
        if (!subsite_manager_move_entity_to_site($sub_entity, $target_site, $access_conversion)) {
            elgg_set_ignore_access($ia);
            access_show_hidden_entities($hidden);
            return false;
        }
    }
    // also move owned (sub) entities
    $options = array("type" => "object", "owner_guid" => $entity->getGUID(), "wheres" => array("(e.guid <> {$entity->getGUID()})"), "limit" => false);
    $batch = new ElggBatch("elgg_get_entities", $options);
    $batch->setIncrementOffset(false);
    foreach ($batch as $sub_entity) {
        if (!subsite_manager_move_entity_to_site($sub_entity, $target_site, $access_conversion)) {
            elgg_set_ignore_access($ia);
            access_show_hidden_entities($hidden);
            return false;
        }
    }
    $dbprefix = elgg_get_config("dbprefix");
    // move access collections
    $query = "UPDATE {$dbprefix}access_collections";
    $query .= " SET site_guid = {$target_site->getGUID()}";
    $query .= " WHERE owner_guid = {$entity->getGUID()}";
    try {
        update_data($query);
    } catch (Exception $e) {
        elgg_log("Subsite manager move entity({$entity->getGUID()}) access collections: " . $e->getMessage(), "ERROR");
        elgg_set_ignore_access($ia);
        access_show_hidden_entities($hidden);
        return false;
    }
    // move annotations
    $query = "UPDATE {$dbprefix}annotations";
    $query .= " SET site_guid = {$target_site->getGUID()}";
    $query .= " WHERE entity_guid = {$entity->getGUID()}";
    try {
        update_data($query);
    } catch (Exception $e) {
        elgg_log("Subsite manager move entity({$entity->getGUID()}) annotations: " . $e->getMessage(), "ERROR");
        elgg_set_ignore_access($ia);
        access_show_hidden_entities($hidden);
        return false;
    }
    // change annotation access
    $query = "UPDATE {$dbprefix}annotations";
    $query .= " SET access_id = {$group_acl}";
    $query .= " WHERE entity_guid = {$entity->getGUID()}";
    $query .= " AND access_id IN (" . implode(", ", $affected_access) . ")";
    try {
        update_data($query);
    } catch (Exception $e) {
        elgg_log("Subsite manager change entity({$entity->getGUID()}) annotation access: " . $e->getMessage(), "ERROR");
        elgg_set_ignore_access($ia);
        access_show_hidden_entities($hidden);
        return false;
    }
    // move river
    $query = "UPDATE {$dbprefix}river";
    $query .= " SET site_guid = {$target_site->getGUID()}";
    $query .= " WHERE subject_guid = {$entity->getGUID()}";
    $query .= " OR object_guid = {$entity->getGUID()}";
    try {
        update_data($query);
    } catch (Exception $e) {
        elgg_log("Subsite manager move entity({$entity->getGUID()}) river: " . $e->getMessage(), "ERROR");
        elgg_set_ignore_access($ia);
        access_show_hidden_entities($hidden);
        return false;
    }
    // change river access
    $query = "UPDATE {$dbprefix}river";
    $query .= " SET access_id = {$group_acl}";
    $query .= " WHERE (subject_guid = {$entity->getGUID()}";
    $query .= " OR object_guid = {$entity->getGUID()})";
    $query .= " AND access_id IN (" . implode(", ", $affected_access) . ")";
    try {
        update_data($query);
    } catch (Exception $e) {
        elgg_log("Subsite manager change entity({$entity->getGUID()}) river access: " . $e->getMessage(), "ERROR");
        elgg_set_ignore_access($ia);
        access_show_hidden_entities($hidden);
        return false;
    }
    // move metadata
    $query = "UPDATE {$dbprefix}metadata";
    $query .= " SET site_guid = {$target_site->getGUID()}";
    $query .= " WHERE entity_guid = {$entity->getGUID()}";
    try {
        update_data($query);
    } catch (Exception $e) {
        elgg_log("Subsite manager move entity({$entity->getGUID()}) metadata: " . $e->getMessage(), "ERROR");
        elgg_set_ignore_access($ia);
        access_show_hidden_entities($hidden);
        return false;
    }
    // change metadata access
    $query = "UPDATE {$dbprefix}metadata";
    $query .= " SET access_id = {$group_acl}";
    $query .= " WHERE entity_guid = {$entity->getGUID()}";
    $query .= " AND access_id IN (" . implode(", ", $affected_access) . ")";
    try {
        update_data($query);
    } catch (Exception $e) {
        elgg_log("Subsite manager change entity({$entity->getGUID()}) metadata access: " . $e->getMessage(), "ERROR");
        elgg_set_ignore_access($ia);
        access_show_hidden_entities($hidden);
        return false;
    }
    // move entity
    $query = "UPDATE {$dbprefix}entities";
    $query .= " SET site_guid = {$target_site->getGUID()}";
    $query .= " WHERE guid = {$entity->getGUID()}";
    try {
        update_data($query);
    } catch (Exception $e) {
        elgg_log("Subsite manager move entity({$entity->getGUID()}) entity: " . $e->getMessage(), "ERROR");
        elgg_set_ignore_access($ia);
        access_show_hidden_entities($hidden);
        return false;
    }
    // change entity access
    $query = "UPDATE {$dbprefix}entities";
    $query .= " SET access_id = {$group_acl}";
    $query .= " WHERE guid = {$entity->getGUID()}";
    $query .= " AND access_id IN (" . implode(", ", $affected_access) . ")";
    try {
        update_data($query);
    } catch (Exception $e) {
        elgg_log("Subsite manager change entity({$entity->getGUID()}) entity access: " . $e->getMessage(), "ERROR");
        elgg_set_ignore_access($ia);
        access_show_hidden_entities($hidden);
        return false;
    }
    // cache cleanup
    _elgg_invalidate_cache_for_entity($entity->getGUID());
    if (!$newentity_cache && is_memcache_available()) {
        $newentity_cache = new ElggMemcache('new_entity_cache');
    }
    if ($newentity_cache) {
        $newentity_cache->delete($entity->getGUID());
    }
    elgg_set_ignore_access($ia);
    access_show_hidden_entities($hidden);
    return true;
}
コード例 #11
0
ファイル: entities.php プロジェクト: pleio/subsite_manager
/**
 * Delete an entity.
 *
 * Removes an entity and its metadata, annotations, relationships, river entries,
 * and private data.
 *
 * Optionally can remove entities contained and owned by $guid.
 *
 * @tip Use ElggEntity::delete() instead.
 *
 * @warning If deleting recursively, this bypasses ownership of items contained by
 * the entity.  That means that if the container_guid = $guid, the item will be deleted
 * regardless of who owns it.
 *
 * @param int  $guid      The guid of the entity to delete
 * @param bool $recursive If true (default) then all entities which are
 *                        owned or contained by $guid will also be deleted.
 *
 * @return bool
 * @access private
 */
function delete_entity($guid, $recursive = true)
{
    global $CONFIG, $ENTITY_CACHE;
    $guid = (int) $guid;
    if ($entity = get_entity($guid)) {
        if (elgg_trigger_event('delete', $entity->type, $entity)) {
            if ($entity->canEdit()) {
                // delete cache
                if (isset($ENTITY_CACHE[$guid])) {
                    _elgg_invalidate_cache_for_entity($guid);
                }
                // If memcache is available then delete this entry from the cache
                static $newentity_cache;
                if (!$newentity_cache && is_memcache_available()) {
                    $newentity_cache = new ElggMemcache('new_entity_cache');
                }
                if ($newentity_cache) {
                    $newentity_cache->delete($guid);
                }
                // Delete contained owned and otherwise releated objects (depth first)
                if ($recursive) {
                    // Temporary token overriding access controls
                    // @todo Do this better.
                    static $__RECURSIVE_DELETE_TOKEN;
                    // Make it slightly harder to guess
                    $__RECURSIVE_DELETE_TOKEN = md5(elgg_get_logged_in_user_guid());
                    $entity_disable_override = access_get_show_hidden_status();
                    access_show_hidden_entities(true);
                    $ia = elgg_set_ignore_access(true);
                    // @todo there was logic in the original code that ignored
                    // entities with owner or container guids of themselves.
                    // this should probably be prevented in ElggEntity instead of checked for here
                    $options = array("limit" => 0, "order_by" => false, "site_guids" => false);
                    foreach (array("site_guid", "container_guid", "owner_guid") as $column) {
                        $options['wheres'] = array("(({$column} = {$guid}) AND guid != {$guid})");
                        $batch = new ElggBatch('elgg_get_entities', $options);
                        $batch->setIncrementOffset(false);
                        foreach ($batch as $e) {
                            $e->delete(true);
                        }
                    }
                    access_show_hidden_entities($entity_disable_override);
                    $__RECURSIVE_DELETE_TOKEN = null;
                    elgg_set_ignore_access($ia);
                }
                // Now delete the entity itself
                $entity->deleteMetadata();
                $entity->deleteOwnedMetadata();
                $entity->deleteAnnotations();
                $entity->deleteOwnedAnnotations();
                $entity->deleteRelationships();
                elgg_delete_river(array('subject_guid' => $guid));
                elgg_delete_river(array('object_guid' => $guid));
                remove_all_private_settings($guid);
                $res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
                if ($res) {
                    $sub_table = "";
                    // Where appropriate delete the sub table
                    switch ($entity->type) {
                        case 'object':
                            $sub_table = $CONFIG->dbprefix . 'objects_entity';
                            break;
                        case 'user':
                            $sub_table = $CONFIG->dbprefix . 'users_entity';
                            break;
                        case 'group':
                            $sub_table = $CONFIG->dbprefix . 'groups_entity';
                            break;
                        case 'site':
                            $sub_table = $CONFIG->dbprefix . 'sites_entity';
                            break;
                    }
                    if ($sub_table) {
                        delete_data("DELETE from {$sub_table} where guid={$guid}");
                    }
                }
                return (bool) $res;
            }
        }
    }
    return false;
}
コード例 #12
0
<?php

/**
 * Bulk delete users by email
 */
$domain = get_input('domain');
$banned = get_input('banned');
$include_enqueued = get_input('include_enqueued');
$s = BulkUserAdmin\DeleteService::getService();
$errors = array();
$count = 0;
$batch = new ElggBatch('bulk_user_admin_get_users', array('domain' => $domain, 'limit' => false, 'enqueued' => 'exclude'));
$batch->setIncrementOffset(false);
foreach ($batch as $user) {
    if (!$user instanceof ElggUser) {
        $errors[] = elgg_echo('bulk_user_admin:error:wrongguid', array($user->guid));
        continue;
    }
    if (!$s->enqueue($user)) {
        $errors[] = elgg_echo('bulk_user_admin:error:enqueue_failed', array($user->name, $user->username, $user->guid));
    }
    $count++;
}
if ($errors) {
    foreach ($errors as $error) {
        register_error($error);
    }
} else {
    system_message(elgg_echo('bulk_user_admin:enqueue:delete', array($count)));
}
forward('/admin/users/bulk_user_admin');
コード例 #13
0
ファイル: TodoList.php プロジェクト: coldtrick/todos
 /**
  * Update the access of todoitems in this list to match the list access
  *
  * @return void
  */
 protected function updateTodoItemAccess()
 {
     $options = array('type' => 'object', 'subtype' => TodoItem::SUBTYPE, 'limit' => false, 'container_guid' => $this->getGUID(), 'wheres' => array('e.access_id <> ' . $this->access_id));
     $ia = elgg_set_ignore_access(true);
     $batch = new ElggBatch('elgg_get_entities', $options);
     $batch->setIncrementOffset(false);
     foreach ($batch as $item) {
         $item->access_id = $this->access_id;
         $item->save();
     }
     elgg_set_ignore_access($ia);
 }
コード例 #14
0
ファイル: ElggEntity.php プロジェクト: sephiroth88/Elgg
 /**
  * Deletes the entity.
  *
  * Removes the entity and its metadata, annotations, relationships,
  * river entries, and private data.
  *
  * Optionally can remove entities contained and owned by this entity.
  *
  * @warning If deleting recursively, this bypasses ownership of items contained by
  * the entity.  That means that if the container_guid = $this->guid, the item will
  * be deleted regardless of who owns it.
  *
  * @param bool $recursive If true (default) then all entities which are
  *                        owned or contained by $this will also be deleted.
  *
  * @return bool
  */
 public function delete($recursive = true)
 {
     global $CONFIG;
     $guid = $this->guid;
     if (!$guid) {
         return false;
     }
     if (!elgg_trigger_event('delete', $this->type, $this)) {
         return false;
     }
     if (!$this->canEdit()) {
         return false;
     }
     _elgg_invalidate_cache_for_entity($guid);
     // If memcache is available then delete this entry from the cache
     static $newentity_cache;
     if (!$newentity_cache && is_memcache_available()) {
         $newentity_cache = new \ElggMemcache('new_entity_cache');
     }
     if ($newentity_cache) {
         $newentity_cache->delete($guid);
     }
     // Delete contained owned and otherwise releated objects (depth first)
     if ($recursive) {
         // Temporary token overriding access controls
         // @todo Do this better.
         static $__RECURSIVE_DELETE_TOKEN;
         // Make it slightly harder to guess
         $__RECURSIVE_DELETE_TOKEN = md5(elgg_get_logged_in_user_guid());
         $entity_disable_override = access_get_show_hidden_status();
         access_show_hidden_entities(true);
         $ia = elgg_set_ignore_access(true);
         // @todo there was logic in the original code that ignored
         // entities with owner or container guids of themselves.
         // this should probably be prevented in \ElggEntity instead of checked for here
         $options = array('wheres' => array("((container_guid = {$guid} OR owner_guid = {$guid} OR site_guid = {$guid})" . " AND guid != {$guid})"), 'limit' => 0);
         $batch = new \ElggBatch('elgg_get_entities', $options);
         $batch->setIncrementOffset(false);
         foreach ($batch as $e) {
             $e->delete(true);
         }
         access_show_hidden_entities($entity_disable_override);
         $__RECURSIVE_DELETE_TOKEN = null;
         elgg_set_ignore_access($ia);
     }
     $entity_disable_override = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     $ia = elgg_set_ignore_access(true);
     // Now delete the entity itself
     $this->deleteMetadata();
     $this->deleteOwnedMetadata();
     $this->deleteAnnotations();
     $this->deleteOwnedAnnotations();
     $this->deleteRelationships();
     access_show_hidden_entities($entity_disable_override);
     elgg_set_ignore_access($ia);
     elgg_delete_river(array('subject_guid' => $guid));
     elgg_delete_river(array('object_guid' => $guid));
     elgg_delete_river(array('target_guid' => $guid));
     remove_all_private_settings($guid);
     $res = $this->getDatabase()->deleteData("DELETE FROM {$CONFIG->dbprefix}entities WHERE guid = {$guid}");
     if ($res) {
         $sub_table = "";
         // Where appropriate delete the sub table
         switch ($this->type) {
             case 'object':
                 $sub_table = $CONFIG->dbprefix . 'objects_entity';
                 break;
             case 'user':
                 $sub_table = $CONFIG->dbprefix . 'users_entity';
                 break;
             case 'group':
                 $sub_table = $CONFIG->dbprefix . 'groups_entity';
                 break;
             case 'site':
                 $sub_table = $CONFIG->dbprefix . 'sites_entity';
                 break;
         }
         if ($sub_table) {
             $this->getDatabase()->deleteData("DELETE FROM {$sub_table} WHERE guid = {$guid}");
         }
     }
     return (bool) $res;
 }
コード例 #15
0
ファイル: functions.php プロジェクト: coldtrick/simplesaml
/**
 * Link a user to a Service Provider (SP), so in the future the user can login using this SP.
 *
 * @param ElggUser $user        the user to link
 * @param string   $saml_source the name of the SP
 * @param string   $saml_uid    the unique ID of the user on the IDentity Provider side
 *
 * @return bool
 */
function simplesaml_link_user(ElggUser $user, $saml_source, $saml_uid)
{
    if (!$user instanceof ElggUser || empty($saml_source) || empty($saml_uid)) {
        return false;
    }
    if (!simplesaml_is_enabled_source($saml_source)) {
        return false;
    }
    // remove links from other users
    $options = ['type' => 'user', 'limit' => false, 'site_guids' => false, 'plugin_id' => 'simplesaml', 'plugin_user_setting_name_value_pairs' => [$saml_source . '_uid' => $saml_uid]];
    $users = new ElggBatch('elgg_get_entities_from_plugin_user_settings', $options);
    $users->setIncrementOffset(false);
    foreach ($users as $other_user) {
        simplesaml_unlink_user($other_user, $saml_source);
    }
    // now save the setting for this user
    return elgg_set_plugin_user_setting("{$saml_source}_uid", $saml_uid, $user->getGUID(), 'simplesaml');
}
コード例 #16
0
ファイル: TidypicsAlbum.php プロジェクト: iionly/tidypics
 /**
  * Delete all the images in this album
  */
 protected function deleteImages()
 {
     $images_count = elgg_get_entities(array("type" => "object", "subtype" => "image", "container_guid" => $this->guid, "count" => true));
     if ($images_count > 0) {
         $images = new ElggBatch('elgg_get_entities', array("type" => "object", "subtype" => "image", "container_guid" => $this->guid, "limit" => ELGG_ENTITIES_NO_VALUE));
         $images->setIncrementOffset(false);
         foreach ($images as $image) {
             if ($image) {
                 $image->delete();
             }
         }
     }
 }
コード例 #17
0
ファイル: reset.php プロジェクト: iionly/elggx_userpoints
<?php

$user_guid = (int) get_input('user_guid');
// Delete all the userpoint objects for the selected user or for all users if user_guid = 0
if ($user_guid > 0) {
    // get all userpoint objects for the selected user and delete them
    $entities = new ElggBatch('elgg_get_entities', array('type' => 'object', 'subtype' => 'userpoint', 'owner_guid' => $user_guid, 'limit' => false));
    $entities->setIncrementOffset(false);
    foreach ($entities as $entity) {
        $entity->delete();
    }
    // and remove the userpoints_points metadata for the selected user
    $options = array('guid' => $user_guid, 'metadata_name' => 'userpoints_points');
    elgg_delete_metadata($options);
} else {
    // get all userpoint objects of all users and delete them
    $entities = new ElggBatch('elgg_get_entities', array('type' => 'object', 'subtype' => 'userpoint', 'limit' => false));
    $entities->setIncrementOffset(false);
    foreach ($entities as $entity) {
        $entity->delete();
    }
    // and also remove all userpoints_points metadata
    $prefix = elgg_get_config('dbprefix');
    delete_data("DELETE from {$prefix}metadata where name_id=" . elgg_get_metastring_id('userpoints_points', true));
}
system_message(elgg_echo("elggx_userpoints:reset:success", array(elgg_echo('elggx_userpoints:lowerplural'))));
forward(REFERER);
コード例 #18
0
    case 'three_months':
        $upper_limit = $now - 60 * 60 * 24 * 91;
        break;
    case 'four_weeks':
        $upper_limit = $now - 60 * 60 * 24 * 29;
        break;
    case 'two_weeks':
        $upper_limit = $now - 60 * 60 * 24 * 15;
        break;
}
if ($upper_limit && $upper_limit > 0) {
    // Fetching events with start_date < $upper_limit here because repeating events have no meaningful real_end_time metadata value
    // Non-scheduled event poll events are not retrieved here because they don't have any fixed start_date metadata value yet
    $options = array('type' => 'object', 'subtype' => 'event_calendar', 'limit' => false, 'metadata_name_value_pairs' => array(array('name' => 'start_date', 'value' => $upper_limit, 'operand' => '<')));
    $past_events = new ElggBatch('elgg_get_entities_from_metadata', $options);
    $past_events->setIncrementOffset(false);
    $success_count = 0;
    $error_count = 0;
    foreach ($past_events as $past_event) {
        // do we delete also repeating events?
        if ($past_event->repeats == 'yes') {
            if ($delete_repeating_events) {
                if ($past_event->delete()) {
                    $success_count++;
                } else {
                    $error_count++;
                }
            }
        } else {
            if ($past_event->repeats != 'yes') {
                // Non-repeating events have a real_end_time metadata value, so let's check if real_end_time < $upper_limit, too, before deletion
コード例 #19
0
ファイル: ElggEntity.php プロジェクト: nirajkaushal/Elgg
 /**
  * Deletes the entity.
  *
  * Removes the entity and its metadata, annotations, relationships,
  * river entries, and private data.
  *
  * Optionally can remove entities contained and owned by this entity.
  *
  * @warning If deleting recursively, this bypasses ownership of items contained by
  * the entity.  That means that if the container_guid = $this->guid, the item will
  * be deleted regardless of who owns it.
  *
  * @param bool $recursive If true (default) then all entities which are
  *                        owned or contained by $this will also be deleted.
  *
  * @return bool
  */
 public function delete($recursive = true)
 {
     global $CONFIG;
     $guid = $this->guid;
     if (!$guid) {
         return false;
     }
     // first check if we can delete this entity
     // NOTE: in Elgg <= 1.10.3 this was after the delete event,
     // which could potentially remove some content if the user didn't have access
     if (!$this->canDelete()) {
         return false;
     }
     // now trigger an event to let others know this entity is about to be deleted
     // so they can prevent it or take their own actions
     if (!_elgg_services()->events->trigger('delete', $this->type, $this)) {
         return false;
     }
     _elgg_invalidate_cache_for_entity($guid);
     // If memcache is available then delete this entry from the cache
     static $newentity_cache;
     if (!$newentity_cache && is_memcache_available()) {
         $newentity_cache = new \ElggMemcache('new_entity_cache');
     }
     if ($newentity_cache) {
         $newentity_cache->delete($guid);
     }
     // Delete contained owned and otherwise releated objects (depth first)
     if ($recursive) {
         // Temporarily overriding access controls
         $entity_disable_override = access_get_show_hidden_status();
         access_show_hidden_entities(true);
         $ia = elgg_set_ignore_access(true);
         // @todo there was logic in the original code that ignored
         // entities with owner or container guids of themselves.
         // this should probably be prevented in \ElggEntity instead of checked for here
         $options = array('wheres' => array("((container_guid = {$guid} OR owner_guid = {$guid} OR site_guid = {$guid})" . " AND guid != {$guid})"), 'limit' => 0);
         $batch = new \ElggBatch('elgg_get_entities', $options);
         $batch->setIncrementOffset(false);
         foreach ($batch as $e) {
             $e->delete(true);
         }
         access_show_hidden_entities($entity_disable_override);
         elgg_set_ignore_access($ia);
     }
     $entity_disable_override = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     $ia = elgg_set_ignore_access(true);
     // Now delete the entity itself
     $this->deleteMetadata();
     $this->deleteOwnedMetadata();
     $this->deleteAnnotations();
     $this->deleteOwnedAnnotations();
     $this->deleteRelationships();
     $this->deleteAccessCollectionMemberships();
     $this->deleteOwnedAccessCollections();
     access_show_hidden_entities($entity_disable_override);
     elgg_set_ignore_access($ia);
     elgg_delete_river(array('subject_guid' => $guid));
     elgg_delete_river(array('object_guid' => $guid));
     elgg_delete_river(array('target_guid' => $guid));
     remove_all_private_settings($guid);
     $res = $this->getDatabase()->deleteData("DELETE FROM {$CONFIG->dbprefix}entities WHERE guid = {$guid}");
     if ($res) {
         $sub_table = "";
         // Where appropriate delete the sub table
         switch ($this->type) {
             case 'object':
                 $sub_table = $CONFIG->dbprefix . 'objects_entity';
                 break;
             case 'user':
                 $sub_table = $CONFIG->dbprefix . 'users_entity';
                 break;
             case 'group':
                 $sub_table = $CONFIG->dbprefix . 'groups_entity';
                 break;
             case 'site':
                 $sub_table = $CONFIG->dbprefix . 'sites_entity';
                 break;
         }
         if ($sub_table) {
             $this->getDatabase()->deleteData("DELETE FROM {$sub_table} WHERE guid = {$guid}");
         }
     }
     _elgg_clear_entity_files($this);
     return (bool) $res;
 }
コード例 #20
0
ファイル: ElggEntity.php プロジェクト: elgg/elgg
 /**
  * Deletes the entity.
  *
  * Removes the entity and its metadata, annotations, relationships,
  * river entries, and private data.
  *
  * Optionally can remove entities contained and owned by this entity.
  *
  * @warning If deleting recursively, this bypasses ownership of items contained by
  * the entity.  That means that if the container_guid = $this->guid, the item will
  * be deleted regardless of who owns it.
  *
  * @param bool $recursive If true (default) then all entities which are
  *                        owned or contained by $this will also be deleted.
  *
  * @return bool
  */
 public function delete($recursive = true)
 {
     $guid = $this->guid;
     if (!$guid) {
         return false;
     }
     // first check if we can delete this entity
     // NOTE: in Elgg <= 1.10.3 this was after the delete event,
     // which could potentially remove some content if the user didn't have access
     if (!$this->canDelete()) {
         return false;
     }
     // now trigger an event to let others know this entity is about to be deleted
     // so they can prevent it or take their own actions
     if (!_elgg_services()->events->trigger('delete', $this->type, $this)) {
         return false;
     }
     if ($this instanceof ElggUser) {
         // ban to prevent using the site during delete
         _elgg_services()->usersTable->markBanned($this->guid, true);
     }
     // Delete contained owned and otherwise releated objects (depth first)
     if ($recursive) {
         // Temporarily overriding access controls
         $entity_disable_override = access_get_show_hidden_status();
         access_show_hidden_entities(true);
         $ia = elgg_set_ignore_access(true);
         // @todo there was logic in the original code that ignored
         // entities with owner or container guids of themselves.
         // this should probably be prevented in \ElggEntity instead of checked for here
         $options = array('wheres' => array("((container_guid = {$guid} OR owner_guid = {$guid})" . " AND guid != {$guid})"), 'limit' => 0);
         $batch = new \ElggBatch('elgg_get_entities', $options);
         $batch->setIncrementOffset(false);
         foreach ($batch as $e) {
             $e->delete(true);
         }
         access_show_hidden_entities($entity_disable_override);
         elgg_set_ignore_access($ia);
     }
     $entity_disable_override = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     $ia = elgg_set_ignore_access(true);
     // Now delete the entity itself
     $this->deleteMetadata();
     $this->deleteOwnedMetadata();
     $this->deleteAnnotations();
     $this->deleteOwnedAnnotations();
     $this->deleteRelationships();
     $this->deleteAccessCollectionMemberships();
     $this->deleteOwnedAccessCollections();
     access_show_hidden_entities($entity_disable_override);
     elgg_set_ignore_access($ia);
     _elgg_delete_river(array('subject_guid' => $guid));
     _elgg_delete_river(array('object_guid' => $guid));
     _elgg_delete_river(array('target_guid' => $guid));
     remove_all_private_settings($guid);
     _elgg_invalidate_cache_for_entity($guid);
     _elgg_invalidate_memcache_for_entity($guid);
     $dbprefix = elgg_get_config('dbprefix');
     $sql = "\n\t\t\tDELETE FROM {$dbprefix}entities\n\t\t\tWHERE guid = :guid\n\t\t";
     $params = [':guid' => $guid];
     $deleted = $this->getDatabase()->deleteData($sql, $params);
     if ($deleted && in_array($this->type, ['object', 'user', 'group', 'site'])) {
         // delete from type-specific subtable
         $sql = "\n\t\t\t\tDELETE FROM {$dbprefix}{$this->type}s_entity\n\t\t\t\tWHERE guid = :guid\n\t\t\t";
         $this->getDatabase()->deleteData($sql, $params);
     }
     _elgg_clear_entity_files($this);
     return (bool) $deleted;
 }
コード例 #21
0
ファイル: delete.php プロジェクト: hypejunction/hypefaker
<?php

set_time_limit(0);
$hidden = access_get_show_hidden_status();
access_show_hidden_entities(true);
$data = new ElggBatch('elgg_get_entities_from_metadata', array('types' => 'user', 'limit' => 0, 'metadata_names' => '__faker'));
$data->setIncrementOffset(false);
foreach ($data as $d) {
    $d->delete(true);
}
$fake_count = elgg_get_entities_from_metadata(array('metadata_names' => '__faker', 'count' => true));
if (!$fake_count) {
    system_message(elgg_echo('faker:delete:success'));
} else {
    register_error(elgg_echo('faker:delete:error', $fake_count));
}
access_show_hidden_entities($hidden);