123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class Deleted_notice extends Managed_DataObject
- {
- public $__table = 'deleted_notice';
- public $id;
- public $profile_id;
- public $uri;
- public $act_created;
- public $created;
- public static function schemaDef()
- {
- return array(
- 'fields' => array(
- 'id' => array('type' => 'int', 'not null' => true, 'description' => 'notice ID'),
- 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile that deleted the notice'),
- 'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'URI of the deleted notice'),
- 'act_created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
- 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was deleted'),
- ),
- 'primary key' => array('id'),
- 'unique keys' => array(
- 'deleted_notice_uri_key' => array('uri'),
- ),
- 'indexes' => array(
- 'deleted_notice_profile_id_idx' => array('profile_id'),
- ),
- );
- }
- public static function addNew(Notice $notice, Profile $actor=null)
- {
- if (is_null($actor)) {
- $actor = $notice->getProfile();
- }
- if ($notice->getProfile()->hasRole(Profile_role::DELETED)) {
-
- return false;
- }
- $act = new Activity();
- $act->verb = ActivityVerb::DELETE;
- $act->time = time();
- $act->id = $notice->getUri();
- $act->content = sprintf(_m('<a href="%1$s">%2$s</a> deleted notice <a href="%3$s">{{%4$s}}</a>.'),
- htmlspecialchars($actor->getUrl()),
- htmlspecialchars($actor->getBestName()),
- htmlspecialchars($notice->getUrl()),
- htmlspecialchars($notice->getUri())
- );
- $act->actor = $actor->asActivityObject();
- $act->target = new ActivityObject();
- $act->target->id = $notice->getUri();
- try {
- $act->target->type = $notice->getObjectType();
- } catch (NoObjectTypeException $e) {
-
- $act->target->type = null;
- }
- $act->objects = array(clone($act->target));
- $url = $notice->getUrl();
- $act->selfLink = $url;
- $act->editLink = $url;
-
-
-
- $stored = Notice::saveActivity($act, $actor);
- return $stored;
- }
- static public function fromStored(Notice $stored)
- {
- $class = get_called_class();
- return self::getByKeys( ['uri' => $stored->getUri()] );
- }
-
- public function getActor()
- {
- return Profile::getByID($this->profile_id);
- }
-
- public function getActorObject()
- {
- return $this->getActor()->asActivityObject();
- }
- static public function getObjectType()
- {
- return 'activity';
- }
- protected $_stored = array();
- public function getStored()
- {
- $uri = $this->getUri();
- if (!isset($this->_stored[$uri])) {
- $this->_stored[$uri] = Notice::getByPK(array('uri' => $uri));
- }
- return $this->_stored[$uri];
- }
- public function getUri()
- {
- return $this->uri;
- }
- public function asActivityObject(Profile $scoped=null)
- {
- $actobj = new ActivityObject();
- $actobj->id = $this->getUri();
- $actobj->type = ActivityObject::ACTIVITY;
- $actobj->actor = $this->getActorObject();
- $actobj->target = new ActivityObject();
- $actobj->target->id = $this->getUri();
-
- $actobj->objects = array(clone($actobj->target));
- $actobj->verb = ActivityVerb::DELETE;
- $actobj->title = ActivityUtils::verbToTitle($actobj->verb);
- $actor = $this->getActor();
-
-
- $actobj->content = sprintf(_m('<a href="%1$s">%2$s</a> deleted notice {{%3$s}}.'),
- htmlspecialchars($actor->getUrl()),
- htmlspecialchars($actor->getFancyName()),
- htmlspecialchars($this->getUri())
- );
- return $actobj;
- }
- static public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
- {
-
-
- $act->target = new ActivityObject();
- $act->target->id = $stored->getUri();
- $act->target->type = $stored->getObjectType();
- $act->objects = array(clone($act->target));
- $act->title = ActivityUtils::verbToTitle($act->verb);
- }
- static public function beforeSchemaUpdate()
- {
- $table = strtolower(get_called_class());
- $schema = Schema::get();
- $schemadef = $schema->getTableDef($table);
-
-
-
- if (!isset($schemadef['fields']['act_uri']) && isset($schemadef['fields']['act_created'])) {
-
- return;
- } elseif (isset($schemadef['fields']['act_uri']) && !isset($schemadef['fields']['act_created'])) {
- throw new ServerException('Something is wrong with your database, you have the act_uri field but NOT act_created in deleted_notice!');
- }
- if (!isset($schemadef['fields']['act_created'])) {
-
- echo "\nFound old $table table, upgrading it to add 'act_created' field...";
- $schemadef['fields']['act_created'] = array('type' => 'datetime', 'not null' => true, 'description' => 'datetime the notice record was created');
- $schemadef['fields']['uri']['length'] = 191;
- $schema->ensureTable($table, $schemadef);
- $deleted = new Deleted_notice();
-
- $deleted->query('UPDATE deleted_notice SET act_created=created;');
- } else {
-
-
- echo "\nFound old $table table, upgrading it to remove 'act_uri' field...";
-
- $deleted = new Deleted_notice();
- $deleted->query('UPDATE deleted_notice SET uri=act_uri;');
- }
- print "DONE.\n";
- print "Resuming core schema upgrade...";
- }
- function insert()
- {
- $result = parent::insert();
- if ($result === false) {
- common_log_db_error($this, 'INSERT', __FILE__);
-
- throw new ServerException('Could not save Deleted_notice');
- }
- }
- }
|