Example #1
0
 public function testCommentAccessSync()
 {
     _elgg_disable_caching_for_entity($this->comment->guid);
     _elgg_disable_caching_for_entity($this->container->guid);
     $this->assertEqual($this->comment->access_id, $this->container->access_id);
     // now change the access of the container
     $this->container->access_id = ACCESS_LOGGED_IN;
     $this->container->save();
     $updated_container = get_entity($this->container->guid);
     $updated_comment = get_entity($this->comment->guid);
     $this->assertEqual($updated_comment->access_id, $updated_container->access_id);
 }
Example #2
0
 /**
  * Update the entity in the database.
  *
  * @return bool Whether the update was successful.
  *
  * @throws InvalidParameterException
  */
 protected function update()
 {
     global $CONFIG;
     // See #5600. This ensures canEdit() checks the BD persisted entity so it sees the
     // persisted owner_guid, container_guid, etc.
     _elgg_disable_caching_for_entity($this->guid);
     $persisted_entity = get_entity($this->guid);
     if (!$persisted_entity) {
         // Why worry about this case? If access control was off when the user fetched this object but
         // was turned back on again. Better to just bail than to turn access control off again.
         return false;
     }
     $allow_edit = $persisted_entity->canEdit();
     unset($persisted_entity);
     if ($allow_edit) {
         // give old update event a chance to stop the update
         $allow_edit = _elgg_services()->events->trigger('update', $this->type, $this);
     }
     _elgg_enable_caching_for_entity($this->guid);
     if (!$allow_edit) {
         return false;
     }
     // See #6225. We copy these after the update event in case a handler changed one of them.
     $guid = (int) $this->guid;
     $owner_guid = (int) $this->owner_guid;
     $access_id = (int) $this->access_id;
     $container_guid = (int) $this->container_guid;
     $time_created = (int) $this->time_created;
     $time = time();
     if ($access_id == ACCESS_DEFAULT) {
         throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
     }
     $ret = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities\n\t\t\tset owner_guid='{$owner_guid}', access_id='{$access_id}',\n\t\t\tcontainer_guid='{$container_guid}', time_created='{$time_created}',\n\t\t\ttime_updated='{$time}' WHERE guid={$guid}");
     elgg_trigger_after_event('update', $this->type, $this);
     // TODO(evan): Move this to \ElggObject?
     if ($this instanceof \ElggObject) {
         update_river_access_by_object($guid, $access_id);
     }
     // 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);
     }
     if ($ret !== false) {
         $this->attributes['time_updated'] = $time;
     }
     _elgg_cache_entity($this);
     $this->orig_attributes = [];
     // Handle cases where there was no error BUT no rows were updated!
     return $ret !== false;
 }
Example #3
0
 /**
  * Override the save function.
  *
  * @return bool
  */
 public function save()
 {
     // Save generic stuff
     if (!parent::save()) {
         return false;
     }
     // Now save specific stuff
     _elgg_disable_caching_for_entity($this->guid);
     $ret = create_group_entity($this->get('guid'), $this->get('name'), $this->get('description'));
     _elgg_enable_caching_for_entity($this->guid);
     return $ret;
 }
Example #4
0
 /**
  * Saves object-specific attributes.
  *
  * @internal Object attributes are saved in the objects_entity table.
  *
  * @return bool
  */
 public function save()
 {
     // Save ElggEntity attributes
     if (!parent::save()) {
         return false;
     }
     // Save ElggObject-specific attributes
     _elgg_disable_caching_for_entity($this->guid);
     $ret = create_object_entity($this->get('guid'), $this->get('title'), $this->get('description'));
     _elgg_enable_caching_for_entity($this->guid);
     return $ret;
 }
Example #5
0
    update_data("UPDATE {$dbprefix}datalists SET value = '{$dataroot}' where name = 'dataroot'");
    update_data("UPDATE {$dbprefix}datalists SET value = '{$path}' where name = 'path'");
    update_data("UPDATE {$dbprefix}sites_entity SET url = '{$url}' where guid = 1");
    update_data("UPDATE {$dbprefix}metastrings SET string = '{$dataroot}'\nWHERE id = (\n   SELECT value_id\n   FROM {$dbprefix}metadata\n   WHERE name_id = (\n      SELECT *\n      FROM (\n         SELECT id\n         FROM {$dbprefix}metastrings\n         WHERE string = 'filestore::dir_root'\n      ) as ms2\n   )\n   LIMIT 1\n)");
    // turn off https login if necessary
    if (strpos($url, 'https') === false) {
        update_data("UPDATE {$dbprefix}config SET value = 'i:0;' where name = 'https_login'");
    }
}
// Invalidate cache
error_log("[elgg_copy] Invalidating cache");
elgg_invalidate_simplecache();
elgg_reset_system_cache();
_elgg_invalidate_cache_for_entity($elgg_copy_plugin->guid);
_elgg_invalidate_memcache_for_entity($elgg_copy_plugin->guid);
_elgg_disable_caching_for_entity($elgg_copy_plugin->guid);
// unset plugins cache
elgg_set_config('plugins_by_id_map', array());
// regenerate plugin entities
error_log("[elgg_copy] Regenerating plugin entities");
_elgg_generate_plugin_entities();
// Update the sandbox settings
error_log("[elgg_copy] Updating elgg_copy plugin settings");
elgg_set_plugin_setting('master_url', $master_url, PLUGIN_ID);
elgg_set_plugin_setting('master_request_key', $master_request_key, PLUGIN_ID);
elgg_set_plugin_setting('request_key', $key, PLUGIN_ID);
elgg_set_plugin_setting('enable_plugins', $enable_plugins, PLUGIN_ID);
elgg_set_plugin_setting('update_mod', $update_mod, PLUGIN_ID);
elgg_set_plugin_setting('mysqldump_path', $mysqldump_path, PLUGIN_ID);
elgg_set_plugin_setting('update_dataroot', $update_dataroot, PLUGIN_ID);
elgg_set_plugin_setting('update_mod', $update_mod, PLUGIN_ID);
Example #6
0
 /**
  * Update the entity in the database.
  *
  * @return bool Whether the update was successful.
  *
  * @throws InvalidParameterException
  */
 protected function update()
 {
     global $CONFIG;
     $guid = (int) $this->guid;
     $owner_guid = (int) $this->owner_guid;
     $access_id = (int) $this->access_id;
     $container_guid = (int) $this->container_guid;
     $time_created = (int) $this->time_created;
     $time = time();
     if ($access_id == ACCESS_DEFAULT) {
         throw new InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
     }
     // See #5600. This ensures the canEdit() check will use a fresh entity from the DB so it sees the
     // persisted owner_guid, container_guid, etc.
     _elgg_disable_caching_for_entity($this->guid);
     $allow_edit = $this->canEdit() && elgg_trigger_event('update', $this->type, $this);
     _elgg_enable_caching_for_entity($this->guid);
     if (!$allow_edit) {
         return false;
     }
     $ret = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities\n\t\t\tset owner_guid='{$owner_guid}', access_id='{$access_id}',\n\t\t\tcontainer_guid='{$container_guid}', time_created='{$time_created}',\n\t\t\ttime_updated='{$time}' WHERE guid={$guid}");
     // TODO(evan): Move this to ElggObject?
     if ($this instanceof ElggObject) {
         update_river_access_by_object($guid, $access_id);
     }
     // 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);
     }
     if ($ret !== false) {
         $this->attributes['time_updated'] = $time;
     }
     _elgg_cache_entity($this);
     // Handle cases where there was no error BUT no rows were updated!
     return $ret !== false;
 }
Example #7
0
 /**
  * Saves this user to the database.
  *
  * @return bool
  */
 public function save()
 {
     // Save generic stuff
     if (!parent::save()) {
         return false;
     }
     // Now save specific stuff
     _elgg_disable_caching_for_entity($this->guid);
     $ret = create_user_entity($this->get('guid'), $this->get('name'), $this->get('username'), $this->get('password'), $this->get('salt'), $this->get('email'), $this->get('language'), $this->get('code'));
     _elgg_enable_caching_for_entity($this->guid);
     return $ret;
 }
Example #8
0
 /**
  * Save an entity.
  *
  * @return bool|int
  * @throws IOException
  */
 public function save()
 {
     $guid = $this->getGUID();
     if ($guid > 0) {
         // See #5600. This ensures the lower level can_edit_entity() check will use a
         // fresh entity from the DB so it sees the persisted owner_guid
         _elgg_disable_caching_for_entity($guid);
         $ret = update_entity($guid, $this->get('owner_guid'), $this->get('access_id'), $this->get('container_guid'), $this->get('time_created'));
         _elgg_enable_caching_for_entity($guid);
         _elgg_cache_entity($this);
         return $ret;
     } else {
         // Create a new entity (nb: using attribute array directly
         // 'cos set function does something special!)
         $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id'], $this->attributes['site_guid'], $this->attributes['container_guid']);
         if (!$this->attributes['guid']) {
             throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed'));
         }
         // Save any unsaved metadata
         // @todo How to capture extra information (access id etc)
         if (sizeof($this->temp_metadata) > 0) {
             foreach ($this->temp_metadata as $name => $value) {
                 $this->{$name} = $value;
                 unset($this->temp_metadata[$name]);
             }
         }
         // Save any unsaved annotations.
         if (sizeof($this->temp_annotations) > 0) {
             foreach ($this->temp_annotations as $name => $value) {
                 $this->annotate($name, $value);
                 unset($this->temp_annotations[$name]);
             }
         }
         // Save any unsaved private settings.
         if (sizeof($this->temp_private_settings) > 0) {
             foreach ($this->temp_private_settings as $name => $value) {
                 $this->setPrivateSetting($name, $value);
                 unset($this->temp_private_settings[$name]);
             }
         }
         // set the subtype to id now rather than a string
         $this->attributes['subtype'] = get_subtype_id($this->attributes['type'], $this->attributes['subtype']);
         _elgg_cache_entity($this);
         return $this->attributes['guid'];
     }
 }