/** * Update the entity in the database. * * @return bool Whether the update was successful. * * @throws InvalidParameterException */ protected function update() { _elgg_services()->boot->invalidateCache($this->guid); if (!$this->canEdit()) { return false; } // give old update event a chance to stop the update if (!_elgg_services()->events->trigger('update', $this->type, $this)) { 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 = $this->getCurrentTime()->getTimestamp(); if ($access_id == ACCESS_DEFAULT) { throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php'); } $ret = _elgg_services()->entityTable->updateRow($guid, (object) ['owner_guid' => $owner_guid, 'container_guid' => $container_guid, 'access_id' => $access_id, 'time_created' => $time_created, 'time_updated' => $time, '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 ($ret !== false) { $this->attributes['time_updated'] = $time; } $this->orig_attributes = []; // Handle cases where there was no error BUT no rows were updated! return $ret !== false; }
/** * Log the current user out * * @return bool */ function logout() { $session = _elgg_services()->session; $user = $session->getLoggedInUser(); if (!$user) { return false; } if (!elgg_trigger_before_event('logout', 'user', $user)) { return false; } // deprecate event $message = "The 'logout' event was deprecated. Register for 'logout:before' or 'logout:after'"; $version = "1.9"; if (!elgg_trigger_deprecated_event('logout', 'user', $user, $message, $version)) { return false; } _elgg_services()->persistentLogin->removePersistentLogin(); // pass along any messages into new session $old_msg = $session->get('msg'); $session->invalidate(); $session->set('msg', $old_msg); elgg_trigger_after_event('logout', 'user', $user); return true; }
/** * 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; }
/** * {@inheritdoc} */ public function save() { $result = false; if (elgg_trigger_before_event('create', 'object', $this)) { $result = parent::save(); if ($result) { elgg_trigger_after_event('create', 'object', $this); } } return $result; }
/** * Send a response * * @param Response $response Response object * @return Response */ public function send(Response $response) { if ($this->response_sent) { if ($this->response_sent !== $response) { _elgg_services()->logger->error('Unable to send the following response: ' . PHP_EOL . (string) $response . PHP_EOL . 'because another response has already been sent: ' . PHP_EOL . (string) $this->response_sent); } } else { if (!elgg_trigger_before_event('send', 'http_response', $response)) { return false; } if (!$this->transport->send($response)) { return false; } elgg_trigger_after_event('send', 'http_response', $response); $this->response_sent = $response; } return $this->response_sent; }
} else { unset_config('debug', $site->getGUID()); } // allow new user registration? $allow_registration = 'on' === get_input('allow_registration', false); set_config('allow_registration', $allow_registration, $site->getGUID()); // setup walled garden $walled_garden = 'on' === get_input('walled_garden', false); set_config('walled_garden', $walled_garden, $site->getGUID()); if ('on' === get_input('https_login')) { set_config('https_login', 1, $site->getGUID()); } else { unset_config('https_login', $site->getGUID()); } $regenerate_site_secret = get_input('regenerate_site_secret', false); if ($regenerate_site_secret) { // if you cancel this even you should present a message to the user if (elgg_trigger_before_event('regenerate_site_secret', 'system')) { init_site_secret(); elgg_reset_system_cache(); elgg_trigger_after_event('regenerate_site_secret', 'system'); system_message(elgg_echo('admin:site:secret_regenerated')); elgg_delete_admin_notice('weak_site_key'); } } if ($site->save()) { system_message(elgg_echo("admin:configuration:success")); } else { register_error(elgg_echo("admin:configuration:fail")); } forward(REFERER);
/** * Create copies of the message in each of participants' inboxes * @return int|false GUID of the sent message or false on error */ public function send() { if (!$this->validate()) { return false; } // Create a sender copy first $owner = $this->getSender(); $this->owner_guid = $owner->guid; // A copy of the message is owned by each of the participants $this->container_guid = $owner->guid; $this->access_id = ACCESS_PRIVATE; // A copy of the message is private to its owner $this->readYet = true; $guid = $this->save(); if (!$guid) { return false; } $this->attach(); // Create a copy for each of the recipients $ia = elgg_set_ignore_access(true); $recipients = $this->getRecipients(); foreach ($recipients as $recipient) { if ($recipient->guid == $owner->guid) { continue; } $copy = clone $this; $copy->owner_guid = $recipient->guid; $copy->container_guid = $recipient->guid; $copy->readYet = false; if ($copy->save()) { $copy->attach(); } } elgg_set_ignore_access($ia); elgg_trigger_after_event('send', 'object', $this); return $guid; }
/** * Log the current user out * * @return bool */ function logout() { $session = _elgg_services()->session; $user = $session->getLoggedInUser(); if (!$user) { return false; } if (!elgg_trigger_before_event('logout', 'user', $user)) { return false; } _elgg_services()->persistentLogin->removePersistentLogin(); // pass along any messages into new session $old_msg = $session->get('msg'); $session->invalidate(); $session->set('msg', $old_msg); elgg_trigger_after_event('logout', 'user', $user); return true; }