Since: 1.9.0
Inheritance: extends HooksRegistrationService, use trait Profilable
コード例 #1
0
 public function tearDown()
 {
     $this->logger->enable();
     $this->session->invalidate();
     $this->events->restore();
     $this->hooks->restore();
 }
コード例 #2
0
ファイル: Annotations.php プロジェクト: elgg/elgg
 /**
  * Update an annotation.
  *
  * @param int    $annotation_id Annotation ID
  * @param string $name          Name of annotation
  * @param string $value         Value of annotation
  * @param string $value_type    Type of value
  * @param int    $owner_guid    Owner of annotation
  * @param int    $access_id     Access level of annotation
  *
  * @return bool
  */
 function update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     $annotation_id = (int) $annotation_id;
     $annotation = $this->get($annotation_id);
     if (!$annotation) {
         return false;
     }
     if (!$annotation->canEdit()) {
         return false;
     }
     $name = trim($name);
     $value_type = detect_extender_valuetype($value, $value_type);
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = $this->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     $sql = "UPDATE {$this->db->prefix}annotations\n\t\t\t(name, value, value_type, access_id, owner_guid)\n\t\t\tVALUES\n\t\t\t(:name, :value, :value_type, :access_id, :owner_guid)\n\t\t\tWHERE id = :annotation_id";
     $result = $this->db->updateData($sql, false, [':name' => $name, ':value' => $value, ':value_type' => $value_type, ':access_id' => $access_id, ':owner_guid' => $owner_guid, ':annotation_id' => $annotation_id]);
     if ($result !== false) {
         // @todo add plugin hook that sends old and new annotation information before db access
         $obj = $this->get($annotation_id);
         $this->events->trigger('update', 'annotation', $obj);
     }
     return $result;
 }
コード例 #3
0
 /**
  * Create a relationship between two entities. E.g. friendship, group membership, site membership.
  *
  * This function lets you make the statement "$guid_one is a $relationship of $guid_two". In the statement,
  * $guid_one is the subject of the relationship, $guid_two is the target, and $relationship is the type.
  *
  * @param int    $guid_one     GUID of the subject entity of the relationship
  * @param string $relationship Type of the relationship
  * @param int    $guid_two     GUID of the target entity of the relationship
  *
  * @return bool
  * @throws \InvalidArgumentException
  */
 public function add($guid_one, $relationship, $guid_two)
 {
     if (strlen($relationship) > \ElggRelationship::RELATIONSHIP_LIMIT) {
         $msg = "relationship name cannot be longer than " . \ElggRelationship::RELATIONSHIP_LIMIT;
         throw new \InvalidArgumentException($msg);
     }
     // Check for duplicates
     // note: escape $relationship after this call, we don't want to double-escape
     if ($this->check($guid_one, $relationship, $guid_two)) {
         return false;
     }
     $guid_one = (int) $guid_one;
     $relationship = $this->db->sanitizeString($relationship);
     $guid_two = (int) $guid_two;
     $time = time();
     $id = $this->db->insertData("\n\t\t\tINSERT INTO {$this->db->getTablePrefix()}entity_relationships\n\t\t\t       (guid_one, relationship, guid_two, time_created)\n\t\t\tVALUES ({$guid_one}, '{$relationship}', {$guid_two}, {$time})\n\t\t\t\tON DUPLICATE KEY UPDATE time_created = {$time}\n\t\t");
     if (!$id) {
         return false;
     }
     $obj = $this->get($id);
     $result = $this->events->trigger('create', 'relationship', $obj);
     if (!$result) {
         $this->delete($id, false);
         return false;
     }
     return true;
 }
コード例 #4
0
ファイル: MetadataTable.php プロジェクト: elgg/elgg
 /**
  * Update a specific piece of metadata.
  *
  * @param int    $id         ID of the metadata to update
  * @param string $name       Metadata name
  * @param string $value      Metadata value
  * @param string $value_type Value type
  * @param int    $owner_guid Owner guid
  * @param int    $access_id  Access ID
  *
  * @return bool
  */
 function update($id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     $id = (int) $id;
     if (!($md = $this->get($id))) {
         return false;
     }
     if (!$md->canEdit()) {
         return false;
     }
     $value_type = detect_extender_valuetype($value, $this->db->sanitizeString(trim($value_type)));
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = $this->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     // Support boolean types (as integers)
     if (is_bool($value)) {
         $value = (int) $value;
     }
     // If ok then add it
     $query = "UPDATE {$this->table}\n\t\t\tSET name = :name,\n\t\t\t    value = :value,\n\t\t\t\tvalue_type = :value_type,\n\t\t\t\taccess_id = :access_id,\n\t\t\t    owner_guid = :owner_guid\n\t\t\tWHERE id = :id";
     $result = $this->db->updateData($query, false, [':name' => $name, ':value' => $value, ':value_type' => $value_type, ':access_id' => $access_id, ':owner_guid' => $owner_guid, ':id' => $id]);
     if ($result !== false) {
         $this->cache->clear($md->entity_guid);
         // @todo this event tells you the metadata has been updated, but does not
         // let you do anything about it. What is needed is a plugin hook before
         // the update that passes old and new values.
         $obj = $this->get($id);
         $this->events->trigger('update', 'metadata', $obj);
     }
     return $result;
 }
コード例 #5
0
ファイル: RelationshipsTable.php プロジェクト: elgg/elgg
 /**
  * Create a relationship between two entities. E.g. friendship, group membership, site membership.
  *
  * This function lets you make the statement "$guid_one is a $relationship of $guid_two". In the statement,
  * $guid_one is the subject of the relationship, $guid_two is the target, and $relationship is the type.
  *
  * @param int    $guid_one     GUID of the subject entity of the relationship
  * @param string $relationship Type of the relationship
  * @param int    $guid_two     GUID of the target entity of the relationship
  * @param bool   $return_id    Return the ID instead of bool?
  *
  * @return bool|int
  * @throws \InvalidArgumentException
  */
 public function add($guid_one, $relationship, $guid_two, $return_id = false)
 {
     if (strlen($relationship) > \ElggRelationship::RELATIONSHIP_LIMIT) {
         $msg = "relationship name cannot be longer than " . \ElggRelationship::RELATIONSHIP_LIMIT;
         throw new \InvalidArgumentException($msg);
     }
     // Check for duplicates
     // note: escape $relationship after this call, we don't want to double-escape
     if ($this->check($guid_one, $relationship, $guid_two)) {
         return false;
     }
     $sql = "\n\t\t\tINSERT INTO {$this->db->prefix}entity_relationships\n\t\t\t       (guid_one, relationship, guid_two, time_created)\n\t\t\tVALUES (:guid1, :relationship, :guid2, :time)\n\t\t\t\tON DUPLICATE KEY UPDATE time_created = :time\n\t\t";
     $params = [':guid1' => (int) $guid_one, ':guid2' => (int) $guid_two, ':relationship' => $relationship, ':time' => $this->getCurrentTime()->getTimestamp()];
     $id = $this->db->insertData($sql, $params);
     if (!$id) {
         return false;
     }
     $obj = $this->get($id);
     $result = $this->events->trigger('create', 'relationship', $obj);
     if (!$result) {
         $this->delete($id, false);
         return false;
     }
     return $return_id ? $obj->id : true;
 }
コード例 #6
0
ファイル: UpgradeService.php プロジェクト: nirajkaushal/Elgg
 /**
  * Upgrades Elgg Database and code
  *
  * @return bool
  */
 protected function processUpgrades()
 {
     $dbversion = (int) $this->datalist->get('version');
     if ($this->upgradeCode($dbversion)) {
         system_message($this->translator->translate('upgrade:core'));
         // Now we trigger an event to give the option for plugins to do something
         $upgrade_details = new \stdClass();
         $upgrade_details->from = $dbversion;
         $upgrade_details->to = elgg_get_version();
         $this->events->trigger('upgrade', 'upgrade', $upgrade_details);
         return true;
     }
     return false;
 }
コード例 #7
0
ファイル: MetadataTable.php プロジェクト: gzachos/elgg_ellak
 /**
  * Update a specific piece of metadata.
  *
  * @param int    $id         ID of the metadata to update
  * @param string $name       Metadata name
  * @param string $value      Metadata value
  * @param string $value_type Value type
  * @param int    $owner_guid Owner guid
  * @param int    $access_id  Access ID
  *
  * @return bool
  */
 function update($id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     $id = (int) $id;
     if (!($md = $this->get($id))) {
         return false;
     }
     if (!$md->canEdit()) {
         return false;
     }
     // If memcached then we invalidate the cache for this entry
     static $metabyname_memcache;
     if (!$metabyname_memcache && is_memcache_available()) {
         $metabyname_memcache = new \ElggMemcache('metabyname_memcache');
     }
     if ($metabyname_memcache) {
         // @todo fix memcache (name_id is not a property of \ElggMetadata)
         $metabyname_memcache->delete("{$md->entity_guid}:{$md->name_id}");
     }
     $value_type = detect_extender_valuetype($value, $this->db->sanitizeString(trim($value_type)));
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = $this->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     // Support boolean types (as integers)
     if (is_bool($value)) {
         $value = (int) $value;
     }
     $value_id = $this->metastringsTable->getId($value);
     if (!$value_id) {
         return false;
     }
     $name_id = $this->metastringsTable->getId($name);
     if (!$name_id) {
         return false;
     }
     // If ok then add it
     $query = "UPDATE {$this->table}" . " set name_id='{$name_id}', value_id='{$value_id}', value_type='{$value_type}', access_id={$access_id}," . " owner_guid={$owner_guid} where id={$id}";
     $result = $this->db->updateData($query);
     if ($result !== false) {
         $this->cache->save($md->entity_guid, $name, $value);
         // @todo this event tells you the metadata has been updated, but does not
         // let you do anything about it. What is needed is a plugin hook before
         // the update that passes old and new values.
         $obj = $this->get($id);
         $this->events->trigger('update', 'metadata', $obj);
     }
     return $result;
 }
コード例 #8
0
ファイル: UsersTable.php プロジェクト: elgg/elgg
 /**
  * Removes user $guid's admin flag.
  *
  * @param int $user_guid User GUID
  * @return bool
  */
 public function removeAdmin($user_guid)
 {
     $user = get_entity($user_guid);
     if (!$user instanceof ElggUser || !$user->canEdit()) {
         return false;
     }
     if (!$this->events->trigger('remove_admin', 'user', $user)) {
         return false;
     }
     $query = "\n\t\t\tUPDATE {$this->table}\n\t\t\tSET admin = 'no'\n\t\t\tWHERE guid = :guid\n\t\t";
     $params = [':guid' => (int) $user_guid];
     _elgg_invalidate_cache_for_entity($user_guid);
     _elgg_invalidate_memcache_for_entity($user_guid);
     if ($this->db->updateData($query, true, $params)) {
         return true;
     }
     return false;
 }
コード例 #9
0
ファイル: EntityTable.php プロジェクト: elgg/elgg
 /**
  * Disables all entities owned and contained by a user (or another entity)
  *
  * @param int $owner_guid The owner GUID
  * @return bool
  */
 public function disableEntities($owner_guid)
 {
     $entity = get_entity($owner_guid);
     if (!$entity || !$entity->canEdit()) {
         return false;
     }
     if (!$this->events->trigger('disable', $entity->type, $entity)) {
         return false;
     }
     $query = "\n\t\t\tUPDATE {$this->table}entities\n\t\t\tSET enabled='no'\n\t\t\tWHERE owner_guid = :owner_guid\n\t\t\tOR container_guid = :owner_guid";
     $params = [':owner_guid' => (int) $owner_guid];
     _elgg_invalidate_cache_for_entity($entity->guid);
     _elgg_invalidate_memcache_for_entity($entity->guid);
     if ($this->db->updateData($query, true, $params)) {
         return true;
     }
     return false;
 }