Exemple #1
0
 /**
  * Load attributes based on database arguments
  *
  * Loads all the DB stuff
  *
  * @param array $args $_REQUEST array
  *
  * @return success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $id = $this->arg('notice');
     $this->notice = Notice::staticGet($id);
     if (empty($this->notice)) {
         // Did we used to have it, and it got deleted?
         $deleted = Deleted_notice::staticGet($id);
         if (!empty($deleted)) {
             $this->clientError(_('Notice deleted.'), 410);
         } else {
             $this->clientError(_('No such notice.'), 404);
         }
         return false;
     }
     $this->profile = $this->notice->getProfile();
     if (empty($this->profile)) {
         $this->serverError(_('Notice has no profile.'), 500);
         return false;
     }
     $this->user = User::staticGet('id', $this->profile->id);
     $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
     return true;
 }
 /**
  * Show the notice
  *
  * @return void
  */
 function showNotice()
 {
     if (!empty($this->notice)) {
         if ($this->format == 'xml') {
             $this->showSingleXmlStatus($this->notice);
         } elseif ($this->format == 'json') {
             $this->show_single_json_status($this->notice);
         }
     } else {
         // XXX: Twitter just sets a 404 header and doens't bother
         // to return an err msg
         $deleted = Deleted_notice::staticGet($this->notice_id);
         if (!empty($deleted)) {
             $this->clientError(_('Status deleted.'), 410, $this->format);
         } else {
             $this->clientError(_('No status with that ID found.'), 404, $this->format);
         }
     }
 }
 /**
  * Show the notice
  *
  * @return void
  */
 function showNotice()
 {
     if (!empty($this->notice)) {
         switch ($this->format) {
             case 'xml':
                 $this->showSingleXmlStatus($this->notice);
                 break;
             case 'json':
                 $this->show_single_json_status($this->notice);
                 break;
             case 'atom':
                 $this->showSingleAtomStatus($this->notice);
                 break;
             default:
                 // TRANS: Exception thrown requesting an unsupported notice output format.
                 // TRANS: %s is the requested output format.
                 throw new Exception(sprintf(_("Unsupported format: %s."), $this->format));
         }
     } else {
         // XXX: Twitter just sets a 404 header and doens't bother
         // to return an err msg
         $deleted = Deleted_notice::getKV($this->notice_id);
         if (!empty($deleted)) {
             $this->clientError(_('Status deleted.'), 410, $this->format);
         } else {
             $this->clientError(_('No status with that ID found.'), 404, $this->format);
         }
     }
 }
Exemple #4
0
 /**
  * Look up the creation timestamp for a given notice ID, even
  * if it's been deleted.
  *
  * @param int $id
  * @return mixed string recorded creation timestamp, or false if can't be found
  */
 public static function getAsTimestamp($id)
 {
     if (!$id) {
         return false;
     }
     $notice = Notice::getKV('id', $id);
     if ($notice) {
         return $notice->created;
     }
     $deleted = Deleted_notice::getKV('id', $id);
     if ($deleted) {
         return $deleted->created;
     }
     return false;
 }
 public function activityObjectFromNotice(Notice $notice)
 {
     $object = Deleted_notice::fromStored($notice);
     return $object->asActivityObject();
 }
Exemple #6
0
 function delete()
 {
     // For auditing purposes, save a record that the notice
     // was deleted.
     // @fixme we have some cases where things get re-run and so the
     // insert fails.
     $deleted = Deleted_notice::staticGet('id', $this->id);
     if (!$deleted) {
         $deleted = new Deleted_notice();
         $deleted->id = $this->id;
         $deleted->profile_id = $this->profile_id;
         $deleted->uri = $this->uri;
         $deleted->created = $this->created;
         $deleted->deleted = common_sql_now();
         $deleted->insert();
     }
     if (Event::handle('NoticeDeleteRelated', array($this))) {
         // Clear related records
         $this->clearReplies();
         $this->clearRepeats();
         $this->clearFaves();
         $this->clearTags();
         $this->clearGroupInboxes();
         // NOTE: we don't clear inboxes
         // NOTE: we don't clear queue items
     }
     $result = parent::delete();
     $this->blowOnDelete();
     return $result;
 }
Exemple #7
0
 function delete()
 {
     // For auditing purposes, save a record that the notice
     // was deleted.
     $deleted = new Deleted_notice();
     $deleted->id = $this->id;
     $deleted->profile_id = $this->profile_id;
     $deleted->uri = $this->uri;
     $deleted->created = $this->created;
     $deleted->deleted = common_sql_now();
     $deleted->insert();
     // Clear related records
     $this->clearReplies();
     $this->clearRepeats();
     $this->clearFaves();
     $this->clearTags();
     $this->clearGroupInboxes();
     // NOTE: we don't clear inboxes
     // NOTE: we don't clear queue items
     $result = parent::delete();
     $this->blowOnDelete();
     return $result;
 }
 /**
  * Fetch the notice to show. This may be overridden by child classes to
  * customize what we fetch without duplicating all of the prepare() method.
  *
  * @return Notice
  */
 protected function getNotice()
 {
     $id = $this->arg('notice');
     $notice = Notice::getKV('id', $id);
     if ($notice instanceof Notice) {
         // Alright, got it!
         return $notice;
     }
     // Did we use to have it, and it got deleted?
     $deleted = Deleted_notice::getKV('id', $id);
     if ($deleted instanceof Deleted_notice) {
         // TRANS: Client error displayed trying to show a deleted notice.
         $this->clientError(_('Notice deleted.'), 410);
     }
     // TRANS: Client error displayed trying to show a non-existing notice.
     $this->clientError(_('No such notice.'), 404);
 }
 public static function beforeSchemaUpdate()
 {
     $table = strtolower(get_called_class());
     $schema = Schema::get();
     $schemadef = $schema->getTableDef($table);
     // 2015-12-31 If we have the act_uri field we want to remove it
     // since there's no difference in delete verbs and the original URI
     // but the act_created field stays.
     if (!isset($schemadef['fields']['act_uri']) && isset($schemadef['fields']['act_created'])) {
         // We don't have an act_uri field, and we also have act_created, so no need to migrate.
         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'])) {
         // this is a "normal" upgrade from StatusNet for example
         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');
         $schema->ensureTable($table, $schemadef);
         $deleted = new Deleted_notice();
         // we don't actually know when the notice was created for the old ones
         $deleted->query('UPDATE deleted_notice SET act_created=created;');
     } else {
         // 2015-10-03 For a while we had act_uri and act_created fields which
         // apparently wasn't necessary.
         echo "\nFound old {$table} table, upgrading it to remove 'act_uri' field...";
         // we stored what should be in 'uri' in the 'act_uri' field for some night-coding reason.
         $deleted = new Deleted_notice();
         $deleted->query('UPDATE deleted_notice SET uri=act_uri;');
     }
     print "DONE.\n";
     print "Resuming core schema upgrade...";
 }
 /**
  * Fetch the notice to show. This may be overridden by child classes to
  * customize what we fetch without duplicating all of the prepare() method.
  *
  * @return Notice
  */
 function getNotice()
 {
     $id = $this->arg('notice');
     $notice = Notice::staticGet('id', $id);
     if (empty($notice)) {
         // Did we used to have it, and it got deleted?
         $deleted = Deleted_notice::staticGet($id);
         if (!empty($deleted)) {
             // TRANS: Client error displayed trying to show a deleted notice.
             $this->clientError(_('Notice deleted.'), 410);
         } else {
             // TRANS: Client error displayed trying to show a non-existing notice.
             $this->clientError(_('No such notice.'), 404);
         }
         return false;
     }
     return $notice;
 }