From: Mikael Nordfeldth Date: Sat, 6 May 2017 11:24:11 +0000 (+0200) Subject: Revert some of 8a4bec811b07a0ed9d76d0aceb03855c91a67242 X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=286b1e0ab76410208bdf3a6dd4fe042e1c497034;p=quix0rs-gnu-social.git Revert some of 8a4bec811b07a0ed9d76d0aceb03855c91a67242 use Notice_prefs instead of adding a new field. The rationale here is simply that the Notice table was _huge_ and I rant into issues with /tmp filling up when altering the tables. So let's just create a new table instead. --- diff --git a/classes/Notice.php b/classes/Notice.php index 1dac58032c..a8561948b4 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -59,7 +59,6 @@ class Notice extends Managed_DataObject public $content; // text public $rendered; // text public $url; // varchar(191) not 255 because utf8mb4 takes more space - public $self; // varchar(191) not 255 because utf8mb4 takes more space public $created; // datetime multiple_key not_null default_0000-00-00%2000%3A00%3A00 public $modified; // timestamp not_null default_CURRENT_TIMESTAMP public $reply_to; // int(4) @@ -84,7 +83,6 @@ class Notice extends Managed_DataObject 'content' => array('type' => 'text', 'description' => 'update content', 'collate' => 'utf8mb4_general_ci'), 'rendered' => array('type' => 'text', 'description' => 'HTML version of the content'), 'url' => array('type' => 'varchar', 'length' => 191, 'description' => 'URL of any attachment (image, video, bookmark, whatever)'), - 'self' => array('type' => 'varchar', 'length' => 191, 'description' => 'Resolvable URL to the (remote) Atom entry representation'), 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'), 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'), 'reply_to' => array('type' => 'int', 'description' => 'notice replied to (usually a guess)'), @@ -328,11 +326,13 @@ class Notice extends Managed_DataObject return common_local_url('ApiStatusesShow', array('id' => $this->getID(), 'format' => 'atom')); } - if (!common_valid_http_url($this->self)) { - throw new InvalidUrlException($this->url); + $selfLink = $this->getPref('ostatus', 'self'); + + if (!common_valid_http_url($selfLink)) { + throw new InvalidUrlException($selfLink); } - return $this->self; + return $selfLink; } public function getObjectType($canonical=false) { @@ -544,9 +544,6 @@ class Notice extends Managed_DataObject $notice->source = $source; $notice->uri = $uri; $notice->url = $url; - if ($self && common_valid_http_url($self)) { - $notice->self = $self; - } // Get the groups here so we can figure out replies and such if (!isset($groups)) { @@ -730,6 +727,10 @@ class Notice extends Managed_DataObject } } + if ($self && common_valid_http_url($self)) { + $notice->setPref('ostatus', 'self', $self); + } + // Only save 'attention' and metadata stuff (URLs, tags...) stuff if // the activityverb is a POST (since stuff like repeat, favorite etc. // reasonably handle notifications themselves. @@ -867,9 +868,6 @@ class Notice extends Managed_DataObject $stored->source = $source; $stored->uri = $uri; $stored->url = $url; - if (common_valid_http_url($stored->self)) { - $stored->self = $self; - } $stored->verb = $act->verb; // we use mb_strlen because it _might_ be that the content is just the string "0"... @@ -1054,6 +1052,10 @@ class Notice extends Managed_DataObject throw new ServerException('Supposedly saved Notice has no ID.'); } + if ($self && common_valid_http_url($self)) { + $stored->setPref('ostatus', 'self', $self); + } + // Only save 'attention' and metadata stuff (URLs, tags...) stuff if // the activityverb is a POST (since stuff like repeat, favorite etc. // reasonably handle notifications themselves. @@ -3238,4 +3240,27 @@ class Notice extends Managed_DataObject } } } + + public function delPref($namespace, $topic) { + return Notice_prefs::setData($this, $namespace, $topic, null); + } + + public function getPref($namespace, $topic, $default=null) { + // If you want an exception to be thrown, call Notice_prefs::getData directly + try { + return Notice_prefs::getData($this, $namespace, $topic, $default); + } catch (NoResultException $e) { + return null; + } + } + + // The same as getPref but will fall back to common_config value for the same namespace/topic + public function getConfigPref($namespace, $topic) + { + return Notice_prefs::getConfigData($this, $namespace, $topic); + } + + public function setPref($namespace, $topic, $data) { + return Notice_prefs::setData($this, $namespace, $topic, $data); + } }