[DATABASE] Update "modified" in Managed_DataObject instead of a DBMS trigger
Instead of relying on the MariaDB's ON UPDATE CURRENT_TIMESTAMP trigger update "modified" attributes in Managed_DataObject. Every raw query that needs adjusting is adjusted, as they won't update "modified" automatically anymore. The main goal behind this change is to fix "modified" updates on PostgreSQL.
This commit is contained in:
parent
341f3d0ea5
commit
ec86de2bc4
|
@ -760,9 +760,12 @@ class File extends Managed_DataObject
|
||||||
if ($file instanceof File) {
|
if ($file instanceof File) {
|
||||||
throw new ServerException('URL already exists in DB');
|
throw new ServerException('URL already exists in DB');
|
||||||
}
|
}
|
||||||
$sql = 'UPDATE %1$s SET urlhash = %2$s, url = %3$s WHERE urlhash = %4$s;';
|
|
||||||
$result = $this->query(sprintf(
|
$result = $this->query(sprintf(
|
||||||
$sql,
|
<<<'END'
|
||||||
|
UPDATE %1$s
|
||||||
|
SET urlhash = %2$s, url = %3$s, modified = CURRENT_TIMESTAMP
|
||||||
|
WHERE urlhash = %4$s;
|
||||||
|
END,
|
||||||
$this->tableName(),
|
$this->tableName(),
|
||||||
$this->_quote((string)self::hashurl($url)),
|
$this->_quote((string)self::hashurl($url)),
|
||||||
$this->_quote((string)$url),
|
$this->_quote((string)$url),
|
||||||
|
@ -939,7 +942,7 @@ class File extends Managed_DataObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "...and now all the non-duplicates which are longer than 191 characters...\n";
|
echo "...and now all the non-duplicates which are longer than 191 characters...\n";
|
||||||
$file->query('UPDATE file SET url=LEFT(url, 191) WHERE LENGTH(url)>191');
|
$file->query('UPDATE file SET url = LEFT(url, 191) WHERE LENGTH(url) > 191');
|
||||||
|
|
||||||
echo "\n...now running hacky pre-schemaupdate change for $table:";
|
echo "\n...now running hacky pre-schemaupdate change for $table:";
|
||||||
// We have to create a urlhash that is _not_ the primary key,
|
// We have to create a urlhash that is _not_ the primary key,
|
||||||
|
@ -973,7 +976,7 @@ class File extends Managed_DataObject
|
||||||
throw new ServerException('Unknown DB type selected.');
|
throw new ServerException('Unknown DB type selected.');
|
||||||
}
|
}
|
||||||
$tablefix->query(sprintf(
|
$tablefix->query(sprintf(
|
||||||
'UPDATE %1$s SET urlhash = %2$s;',
|
'UPDATE %1$s SET urlhash = %2$s, modified = CURRENT_TIMESTAMP;',
|
||||||
$tablefix->escapedTableName(),
|
$tablefix->escapedTableName(),
|
||||||
$url_sha256
|
$url_sha256
|
||||||
));
|
));
|
||||||
|
|
|
@ -468,7 +468,7 @@ class File_redirection extends Managed_DataObject
|
||||||
throw new ServerException('Unknown DB type selected.');
|
throw new ServerException('Unknown DB type selected.');
|
||||||
}
|
}
|
||||||
$tablefix->query(sprintf(
|
$tablefix->query(sprintf(
|
||||||
'UPDATE %1$s SET urlhash = %2$s;',
|
'UPDATE %1$s SET urlhash = %2$s, modified = CURRENT_TIMESTAMP;',
|
||||||
$tablefix->escapedTableName(),
|
$tablefix->escapedTableName(),
|
||||||
$url_sha256
|
$url_sha256
|
||||||
));
|
));
|
||||||
|
|
|
@ -74,15 +74,20 @@ class Local_group extends Managed_DataObject
|
||||||
public function setNickname($nickname)
|
public function setNickname($nickname)
|
||||||
{
|
{
|
||||||
$this->decache();
|
$this->decache();
|
||||||
|
$modified = common_sql_now();
|
||||||
$result = $this->query(sprintf(
|
$result = $this->query(sprintf(
|
||||||
'UPDATE local_group SET nickname = %1$s WHERE group_id = %2$d;',
|
<<<'END'
|
||||||
|
UPDATE local_group SET nickname = %1$s, modified = %2$s
|
||||||
|
WHERE group_id = %3$d;
|
||||||
|
END,
|
||||||
$this->_quote($nickname),
|
$this->_quote($nickname),
|
||||||
|
$this->_quote($modified),
|
||||||
$this->group_id
|
$this->group_id
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$this->nickname = $nickname;
|
$this->nickname = $nickname;
|
||||||
$this->fixupTimestamps();
|
$this->modified = $modified;
|
||||||
$this->encache();
|
$this->encache();
|
||||||
} else {
|
} else {
|
||||||
common_log_db_error($local, 'UPDATE', __FILE__);
|
common_log_db_error($local, 'UPDATE', __FILE__);
|
||||||
|
|
|
@ -522,6 +522,25 @@ abstract class Managed_DataObject extends Memcached_DataObject
|
||||||
return $aliases;
|
return $aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the attribute defined as "timestamp" to CURRENT_TIMESTAMP.
|
||||||
|
* This is hooked in update() and updateWithKeys() to update "modified".
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function updateAutoTimestamps(): void
|
||||||
|
{
|
||||||
|
$table = static::schemaDef();
|
||||||
|
foreach ($table['fields'] as $name => $col) {
|
||||||
|
if ($col['type'] === 'timestamp'
|
||||||
|
&& !array_key_exists('default', $col)
|
||||||
|
&& !isset($this->$name)) {
|
||||||
|
$this->$name = common_sql_now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update() won't write key columns, so we have to do it ourselves.
|
* update() won't write key columns, so we have to do it ourselves.
|
||||||
* This also automatically calls "update" _before_ it sets the keys.
|
* This also automatically calls "update" _before_ it sets the keys.
|
||||||
|
@ -548,6 +567,10 @@ abstract class Managed_DataObject extends Memcached_DataObject
|
||||||
// do it in a transaction
|
// do it in a transaction
|
||||||
$this->query('START TRANSACTION');
|
$this->query('START TRANSACTION');
|
||||||
|
|
||||||
|
// ON UPDATE CURRENT_TIMESTAMP behaviour
|
||||||
|
// @fixme Should the value be reverted back if transaction failed?
|
||||||
|
$this->updateAutoTimestamps();
|
||||||
|
|
||||||
$parts = [];
|
$parts = [];
|
||||||
foreach ($this->keys() as $k) {
|
foreach ($this->keys() as $k) {
|
||||||
$v = $this->table()[$k];
|
$v = $this->table()[$k];
|
||||||
|
@ -664,12 +687,25 @@ abstract class Managed_DataObject extends Memcached_DataObject
|
||||||
public function insert()
|
public function insert()
|
||||||
{
|
{
|
||||||
$this->onInsert();
|
$this->onInsert();
|
||||||
return parent::insert();
|
$result = parent::insert();
|
||||||
|
|
||||||
|
// Make this object aware of the changed "modified" attribute.
|
||||||
|
// Sets it approximately to the same value as DEFAULT CURRENT_TIMESTAMP
|
||||||
|
// just did (@fixme).
|
||||||
|
if ($result) {
|
||||||
|
$this->updateAutoTimestamps();
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update($dataObject=false)
|
public function update($dataObject = false)
|
||||||
{
|
{
|
||||||
$this->onUpdate($dataObject);
|
$this->onUpdate($dataObject);
|
||||||
|
|
||||||
|
// ON UPDATE CURRENT_TIMESTAMP behaviour
|
||||||
|
// @fixme Should the value be reverted back if transaction failed?
|
||||||
|
$this->updateAutoTimestamps();
|
||||||
|
|
||||||
return parent::update($dataObject);
|
return parent::update($dataObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,7 +443,6 @@ class Memcached_DataObject extends Safe_DataObject
|
||||||
{
|
{
|
||||||
$result = parent::insert();
|
$result = parent::insert();
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$this->fixupTimestamps();
|
|
||||||
$this->encache(); // in case of cached negative lookups
|
$this->encache(); // in case of cached negative lookups
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -456,7 +455,6 @@ class Memcached_DataObject extends Safe_DataObject
|
||||||
}
|
}
|
||||||
$result = parent::update($dataObject);
|
$result = parent::update($dataObject);
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
$this->fixupTimestamps();
|
|
||||||
$this->encache();
|
$this->encache();
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -931,22 +929,6 @@ class Memcached_DataObject extends Safe_DataObject
|
||||||
return $c->delete($cacheKey);
|
return $c->delete($cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fixupTimestamps()
|
|
||||||
{
|
|
||||||
// Fake up timestamp columns
|
|
||||||
$columns = $this->table();
|
|
||||||
foreach ($columns as $name => $type) {
|
|
||||||
if ($type & DB_DATAOBJECT_MYSQLTIMESTAMP) {
|
|
||||||
$this->$name = common_sql_now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function debugDump()
|
|
||||||
{
|
|
||||||
common_debug("debugDump: " . common_log_objstring($this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function raiseError($message, $type = null, $behavior = null)
|
public function raiseError($message, $type = null, $behavior = null)
|
||||||
{
|
{
|
||||||
$id = get_class($this);
|
$id = get_class($this);
|
||||||
|
|
|
@ -3243,7 +3243,11 @@ class Notice extends Managed_DataObject
|
||||||
unset($notice);
|
unset($notice);
|
||||||
$notice = new Notice();
|
$notice = new Notice();
|
||||||
$notice->query(sprintf(
|
$notice->query(sprintf(
|
||||||
'UPDATE %1$s SET %2$s = NULL WHERE id IN (%3$s)',
|
<<<'END'
|
||||||
|
UPDATE %1$s
|
||||||
|
SET %2$s = NULL, modified = CURRENT_TIMESTAMP
|
||||||
|
WHERE id IN (%3$s)
|
||||||
|
END,
|
||||||
$notice->escapedTableName(),
|
$notice->escapedTableName(),
|
||||||
$field,
|
$field,
|
||||||
implode(',', $ids)
|
implode(',', $ids)
|
||||||
|
|
|
@ -86,6 +86,7 @@ class Oauth_application_user extends Managed_DataObject
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$toupdate = implode(', ', $parts);
|
$toupdate = implode(', ', $parts);
|
||||||
|
$toupdate .= ', modified = CURRENT_TIMESTAMP';
|
||||||
|
|
||||||
$table = $this->tableName();
|
$table = $this->tableName();
|
||||||
$tableName = $this->escapedTableName();
|
$tableName = $this->escapedTableName();
|
||||||
|
|
|
@ -292,14 +292,16 @@ class Profile_tag extends Managed_DataObject
|
||||||
public static function moveTag($orig, $new)
|
public static function moveTag($orig, $new)
|
||||||
{
|
{
|
||||||
$tags = new Profile_tag();
|
$tags = new Profile_tag();
|
||||||
$qry = "UPDATE profile_tag SET tag = '%s', tagger = '%s' " .
|
|
||||||
"WHERE tag = '%s' AND tagger = '%s'";
|
|
||||||
$result = $tags->query(sprintf(
|
$result = $tags->query(sprintf(
|
||||||
$qry,
|
<<<'END'
|
||||||
$tags->escape($new->tag),
|
UPDATE profile_tag
|
||||||
$tags->escape($new->tagger),
|
SET tag = %1$s, tagger = %2$s, modified = CURRENT_TIMESTAMP
|
||||||
$tags->escape($orig->tag),
|
WHERE tag = %3$s AND tagger = %4$s
|
||||||
$tags->escape($orig->tagger)
|
END,
|
||||||
|
$tags->_quote($new->tag),
|
||||||
|
$tags->_quote($new->tagger),
|
||||||
|
$tags->_quote($orig->tag),
|
||||||
|
$tags->_quote($orig->tagger)
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
|
|
|
@ -104,11 +104,22 @@ class Queue_item extends Managed_DataObject
|
||||||
*/
|
*/
|
||||||
public function releaseClaim()
|
public function releaseClaim()
|
||||||
{
|
{
|
||||||
// DB_DataObject doesn't let us save nulls right now
|
$modified = common_sql_now();
|
||||||
$sql = sprintf("UPDATE queue_item SET claimed=NULL WHERE id=%d", $this->getID());
|
// @fixme Consider $this->sqlValue('NULL')
|
||||||
$this->query($sql);
|
$ret = $this->query(sprintf(
|
||||||
|
<<<'END'
|
||||||
|
UPDATE queue_item
|
||||||
|
SET claimed = NULL, modified = %1$s
|
||||||
|
WHERE id = %2$d
|
||||||
|
END,
|
||||||
|
$this->_quote($modified),
|
||||||
|
$this->getID()
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($ret) {
|
||||||
$this->claimed = null;
|
$this->claimed = null;
|
||||||
|
$this->modified = $modified;
|
||||||
$this->encache();
|
$this->encache();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,12 +145,6 @@ class MysqlSchema extends Schema
|
||||||
if (preg_match('/(^|\s)auto_increment(\s|$)/i', $extra)) {
|
if (preg_match('/(^|\s)auto_increment(\s|$)/i', $extra)) {
|
||||||
$field['auto_increment'] = true;
|
$field['auto_increment'] = true;
|
||||||
}
|
}
|
||||||
if (preg_match(
|
|
||||||
'/(^|\s)on update CURRENT_TIMESTAMP(\(\))?(\s|$)/i',
|
|
||||||
$extra
|
|
||||||
)) {
|
|
||||||
$field['auto_update_timestamp'] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$table_props = $this->getTableProperties($table, ['TABLE_COLLATION']);
|
$table_props = $this->getTableProperties($table, ['TABLE_COLLATION']);
|
||||||
|
@ -519,10 +513,6 @@ class MysqlSchema extends Schema
|
||||||
if (!empty($cd['auto_increment'])) {
|
if (!empty($cd['auto_increment'])) {
|
||||||
$line[] = 'AUTO_INCREMENT';
|
$line[] = 'AUTO_INCREMENT';
|
||||||
}
|
}
|
||||||
// This'll have been added from our transform of "timestamp" type
|
|
||||||
if (!empty($cd['auto_update_timestamp'])) {
|
|
||||||
$line[] = 'ON UPDATE CURRENT_TIMESTAMP';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($cd['description'])) {
|
if (!empty($cd['description'])) {
|
||||||
$line[] = 'COMMENT';
|
$line[] = 'COMMENT';
|
||||||
|
|
|
@ -1043,7 +1043,6 @@ class Schema
|
||||||
$col['type'] = 'datetime';
|
$col['type'] = 'datetime';
|
||||||
if (!array_key_exists('default', $col)) {
|
if (!array_key_exists('default', $col)) {
|
||||||
$col['default'] = 'CURRENT_TIMESTAMP';
|
$col['default'] = 'CURRENT_TIMESTAMP';
|
||||||
// FIXME: PostgreSQL support.
|
|
||||||
$col['auto_update_timestamp'] = true;
|
$col['auto_update_timestamp'] = true;
|
||||||
}
|
}
|
||||||
// no break
|
// no break
|
||||||
|
|
|
@ -116,10 +116,15 @@ while ($fn->fetch()) {
|
||||||
echo " (unchanged, but embedding lookup failed)\n";
|
echo " (unchanged, but embedding lookup failed)\n";
|
||||||
}
|
}
|
||||||
} elseif (!$dry) {
|
} elseif (!$dry) {
|
||||||
$sql = "UPDATE file " .
|
$f->query(sprintf(
|
||||||
"SET mimetype=null, title=null,size=null,protected=null " .
|
<<<'END'
|
||||||
"WHERE id={$f->id}";
|
UPDATE file
|
||||||
$f->query($sql);
|
SET mimetype = NULL, title = NULL, size = NULL,
|
||||||
|
protected = NULL, modified = CURRENT_TIMESTAMP
|
||||||
|
WHERE id = %d
|
||||||
|
END,
|
||||||
|
$f->getID()
|
||||||
|
));
|
||||||
$f->decache();
|
$f->decache();
|
||||||
if ($data instanceof File_embed) {
|
if ($data instanceof File_embed) {
|
||||||
$fetch = true;
|
$fetch = true;
|
||||||
|
@ -144,12 +149,18 @@ while ($fn->fetch()) {
|
||||||
echo "Found broken file with ";
|
echo "Found broken file with ";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "ID: {$f->id}, URL {$f->url}\n";
|
echo "ID: {$f->getID()}, URL {$f->url}\n";
|
||||||
if (!$dry) {
|
if (!$dry) {
|
||||||
$fetch = true;
|
$fetch = true;
|
||||||
$sql = "UPDATE file SET title=null, size=null, protected=null " .
|
$f->query(sprintf(
|
||||||
"WHERE id={$f->id}";
|
<<<'END'
|
||||||
$f->query($sql);
|
UPDATE file
|
||||||
|
SET title = NULL, size = NULL,
|
||||||
|
protected = NULL, modified = CURRENT_TIMESTAMP
|
||||||
|
WHERE id = %d,
|
||||||
|
END,
|
||||||
|
$f->getID()
|
||||||
|
));
|
||||||
$f->decache();
|
$f->decache();
|
||||||
|
|
||||||
if ($data instanceof File_embed) {
|
if ($data instanceof File_embed) {
|
||||||
|
@ -159,7 +170,7 @@ while ($fn->fetch()) {
|
||||||
|
|
||||||
if ($thumb instanceof File_thumbnail) {
|
if ($thumb instanceof File_thumbnail) {
|
||||||
// Delete all thumbnails, not just this one
|
// Delete all thumbnails, not just this one
|
||||||
$f->query("DELETE from file_thumbnail WHERE file_id = {$f->id}");
|
$f->query("DELETE FROM file_thumbnail WHERE file_id = {$f->getID()}");
|
||||||
$thumb->decache();
|
$thumb->decache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,9 +109,10 @@ if ($feedurl != $oprofile->feeduri || $salmonuri != $oprofile->salmonuri) {
|
||||||
$ok = $oprofile->query(
|
$ok = $oprofile->query(
|
||||||
<<<END
|
<<<END
|
||||||
UPDATE ostatus_profile
|
UPDATE ostatus_profile
|
||||||
SET feeduri = '{$oprofile->escape($feedurl)}',
|
SET feeduri = {$oprofile->_quote($feedurl)},
|
||||||
salmonuri = '{$oprofile->escape($salmonuri)}'
|
salmonuri = {$oprofile->_quote($salmonuri)},
|
||||||
WHERE uri = '{$oprofile->escape($uri)}'
|
modified = CURRENT_TIMESTAMP
|
||||||
|
WHERE uri = {$oprofile->_quote($uri)}
|
||||||
END
|
END
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,45 +1,39 @@
|
||||||
<?php
|
<?php
|
||||||
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
|
//
|
||||||
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GNU social is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StatusNet, the distributed open-source microblogging tool
|
|
||||||
*
|
|
||||||
* Class to ping an rssCloud endpoint when a feed has been updated
|
* Class to ping an rssCloud endpoint when a feed has been updated
|
||||||
*
|
*
|
||||||
* PHP version 5
|
|
||||||
*
|
|
||||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* @category Plugin
|
* @category Plugin
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Zach Copley <zach@status.net>
|
* @author Zach Copley <zach@status.net>
|
||||||
* @copyright 2009 StatusNet, Inc.
|
* @copyright 2009 StatusNet, Inc.
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* @link http://status.net/
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
defined('STATUSNET') || die();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for notifying cloud-enabled RSS aggregators that StatusNet
|
* Class for notifying cloud-enabled RSS aggregators that StatusNet
|
||||||
* feeds have been updated.
|
* feeds have been updated.
|
||||||
*
|
*
|
||||||
* @category Plugin
|
* @category Plugin
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Zach Copley <zach@status.net>
|
* @author Zach Copley <zach@status.net>
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* @link http://status.net/
|
|
||||||
*/
|
*/
|
||||||
class RSSCloudNotifier
|
class RSSCloudNotifier
|
||||||
{
|
{
|
||||||
|
@ -54,7 +48,7 @@ class RSSCloudNotifier
|
||||||
*
|
*
|
||||||
* @return boolean success
|
* @return boolean success
|
||||||
*/
|
*/
|
||||||
function challenge($endpoint, $feed)
|
public function challenge($endpoint, $feed)
|
||||||
{
|
{
|
||||||
$code = common_confirmation_code(128);
|
$code = common_confirmation_code(128);
|
||||||
$params = array('url' => $feed, 'challenge' => $code);
|
$params = array('url' => $feed, 'challenge' => $code);
|
||||||
|
@ -64,9 +58,11 @@ class RSSCloudNotifier
|
||||||
$client = new HTTPClient();
|
$client = new HTTPClient();
|
||||||
$response = $client->get($url);
|
$response = $client->get($url);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_log(LOG_INFO,
|
common_log(
|
||||||
'RSSCloud plugin - failure testing notify handler ' .
|
LOG_INFO,
|
||||||
$endpoint . ' - ' . $e->getMessage());
|
'RSSCloud plugin - failure testing notify handler '
|
||||||
|
. $endpoint . ' - ' . $e->getMessage()
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +106,7 @@ class RSSCloudNotifier
|
||||||
*
|
*
|
||||||
* @return boolean success
|
* @return boolean success
|
||||||
*/
|
*/
|
||||||
function postUpdate($endpoint, $feed)
|
public function postUpdate($endpoint, $feed)
|
||||||
{
|
{
|
||||||
$headers = array();
|
$headers = array();
|
||||||
$postdata = array('url' => $feed);
|
$postdata = array('url' => $feed);
|
||||||
|
@ -147,7 +143,7 @@ class RSSCloudNotifier
|
||||||
*
|
*
|
||||||
* @return boolean success
|
* @return boolean success
|
||||||
*/
|
*/
|
||||||
function notify($profile)
|
public function notify($profile)
|
||||||
{
|
{
|
||||||
$feed = common_path('api/statuses/user_timeline/') .
|
$feed = common_path('api/statuses/user_timeline/') .
|
||||||
$profile->id . '.rss';
|
$profile->id . '.rss';
|
||||||
|
@ -180,18 +176,16 @@ class RSSCloudNotifier
|
||||||
*
|
*
|
||||||
* @return boolean success
|
* @return boolean success
|
||||||
*/
|
*/
|
||||||
function handleFailure($cloudSub)
|
public function handleFailure($cloudSub)
|
||||||
{
|
{
|
||||||
$failCnt = $cloudSub->failures + 1;
|
$failCnt = $cloudSub->failures + 1;
|
||||||
|
|
||||||
if ($failCnt == self::MAX_FAILURES) {
|
if ($failCnt == self::MAX_FAILURES) {
|
||||||
|
common_log(
|
||||||
common_log(LOG_INFO,
|
LOG_INFO,
|
||||||
'Deleting RSSCloud subcription ' .
|
'Deleting RSSCloud subcription (max failure count reached), '
|
||||||
'(max failure count reached), profile: ' .
|
. "profile: {$cloudSub->subscribed} handler: {$cloudSub->url}"
|
||||||
$cloudSub->subscribed .
|
);
|
||||||
' handler: ' .
|
|
||||||
$cloudSub->url);
|
|
||||||
|
|
||||||
// XXX: WTF! ->delete() doesn't work. Clearly, there are some issues with
|
// XXX: WTF! ->delete() doesn't work. Clearly, there are some issues with
|
||||||
// the DB_DataObject, or my understanding of it. Have to drop into SQL.
|
// the DB_DataObject, or my understanding of it. Have to drop into SQL.
|
||||||
|
@ -216,18 +210,23 @@ class RSSCloudNotifier
|
||||||
|
|
||||||
// XXX: ->update() not working either, gar!
|
// XXX: ->update() not working either, gar!
|
||||||
|
|
||||||
$qry = 'UPDATE rsscloud_subscription' .
|
$result = $cloudSub->query(sprintf(
|
||||||
' SET failures = ' . $failCnt .
|
<<<'END'
|
||||||
' WHERE subscribed = ' . $cloudSub->subscribed .
|
UPDATE rsscloud_subscription
|
||||||
' AND url = \'' . $cloudSub->url . '\'';
|
SET failures = %1$d, modified = CURRENT_TIMESTAMP
|
||||||
|
WHERE subscribed = %2$d AND url = %3$s
|
||||||
$result = $cloudSub->query($qry);
|
END,
|
||||||
|
$failCnt,
|
||||||
|
$cloudSub->subscribed,
|
||||||
|
$cloudSub->_quote($cloudSub->url)
|
||||||
|
));
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
common_log_db_error($cloudsub, 'UPDATE', __FILE__);
|
common_log_db_error($cloudsub, 'UPDATE', __FILE__);
|
||||||
common_log(LOG_ERR,
|
common_log(
|
||||||
'Could not update failure ' .
|
LOG_ERR,
|
||||||
'count on RSSCloud subscription');
|
'Could not update failure count on RSSCloud subscription'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,10 +89,14 @@ class ClearflagAction extends ProfileFormAction
|
||||||
{
|
{
|
||||||
$ufp = new User_flag_profile();
|
$ufp = new User_flag_profile();
|
||||||
|
|
||||||
$result = $ufp->query('UPDATE user_flag_profile ' .
|
$result = $ufp->query(sprintf(
|
||||||
'SET cleared = CURRENT_TIMESTAMP ' .
|
<<<'END'
|
||||||
'WHERE cleared IS NULL ' .
|
UPDATE user_flag_profile
|
||||||
'AND profile_id = ' . $this->profile->id);
|
SET cleared = CURRENT_TIMESTAMP, modified = cleared
|
||||||
|
WHERE cleared IS NULL AND profile_id = %d
|
||||||
|
END,
|
||||||
|
$this->profile->getID()
|
||||||
|
));
|
||||||
|
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
// TRANS: Server exception given when flags could not be cleared.
|
// TRANS: Server exception given when flags could not be cleared.
|
||||||
|
|
|
@ -104,10 +104,15 @@ if ($notice->N) {
|
||||||
// but we're going to have to decache them individually anyway and
|
// but we're going to have to decache them individually anyway and
|
||||||
// it doesn't hurt to make sure we don't hold up replication with
|
// it doesn't hurt to make sure we don't hold up replication with
|
||||||
// what might be a very slow single UPDATE.
|
// what might be a very slow single UPDATE.
|
||||||
$query = sprintf('UPDATE notice ' .
|
$ok = $update->query(sprintf(
|
||||||
'SET lat=NULL,lon=NULL,location_ns=NULL,location_id=NULL ' .
|
<<<'END'
|
||||||
'WHERE id=%d', $notice->id);
|
UPDATE notice
|
||||||
$ok = $update->query($query);
|
SET lat = NULL, lon = NULL, location_ns = NULL, location_id = NULL
|
||||||
|
modified = CURRENT_TIMESTAMP
|
||||||
|
WHERE id = %d
|
||||||
|
END,
|
||||||
|
$notice->getID()
|
||||||
|
));
|
||||||
if ($ok) {
|
if ($ok) {
|
||||||
// And now we decache him manually, as query() doesn't know what we're doing...
|
// And now we decache him manually, as query() doesn't know what we're doing...
|
||||||
$orig->decache();
|
$orig->decache();
|
||||||
|
|
|
@ -131,9 +131,16 @@ function fixupUserBadNulls(): void
|
||||||
|
|
||||||
if ($user->find()) {
|
if ($user->find()) {
|
||||||
while ($user->fetch()) {
|
while ($user->fetch()) {
|
||||||
$sql = "UPDATE {$user->escapedTableName()} SET {$col} = NULL "
|
$user->query(sprintf(
|
||||||
. "WHERE id = {$user->id}";
|
<<<'END'
|
||||||
$user->query($sql);
|
UPDATE %1$s
|
||||||
|
SET %2$s = NULL, modified = CURRENT_TIMESTAMP
|
||||||
|
WHERE id = %3$d
|
||||||
|
END,
|
||||||
|
$user->escapedTableName(),
|
||||||
|
$col,
|
||||||
|
$user->getID()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,8 +276,12 @@ function fixupConversationURIs()
|
||||||
while ($conv->fetch()) {
|
while ($conv->fetch()) {
|
||||||
$uri = common_local_url('conversation', ['id' => $conv->id]);
|
$uri = common_local_url('conversation', ['id' => $conv->id]);
|
||||||
$sql = sprintf(
|
$sql = sprintf(
|
||||||
'UPDATE conversation SET uri = \'%1$s\' WHERE id = %2$d;',
|
<<<'END'
|
||||||
$conv->escape($uri),
|
UPDATE conversation
|
||||||
|
SET uri = %1$s, modified = CURRENT_TIMESTAMP
|
||||||
|
WHERE id = %2$d;
|
||||||
|
END,
|
||||||
|
$conv->_quote($uri),
|
||||||
$conv->id
|
$conv->id
|
||||||
);
|
);
|
||||||
$conv->query($sql);
|
$conv->query($sql);
|
||||||
|
@ -310,7 +321,15 @@ function initGroupProfileId()
|
||||||
$profile->query('ROLLBACK');
|
$profile->query('ROLLBACK');
|
||||||
throw new Exception('Profile insertion failed, profileurl: '.$profile->profileurl);
|
throw new Exception('Profile insertion failed, profileurl: '.$profile->profileurl);
|
||||||
}
|
}
|
||||||
$group->query("UPDATE user_group SET profile_id={$id} WHERE id={$group->id}");
|
$group->query(sprintf(
|
||||||
|
<<<'END'
|
||||||
|
UPDATE user_group
|
||||||
|
SET profile_id = %1$d, modified = CURRENT_TIMESTAMP
|
||||||
|
WHERE id = %2$d
|
||||||
|
END,
|
||||||
|
$id,
|
||||||
|
$group->getID()
|
||||||
|
));
|
||||||
$profile->query('COMMIT');
|
$profile->query('COMMIT');
|
||||||
|
|
||||||
$profile->free();
|
$profile->free();
|
||||||
|
@ -400,18 +419,24 @@ function initSubscriptionURI()
|
||||||
if ($sub->find()) {
|
if ($sub->find()) {
|
||||||
while ($sub->fetch()) {
|
while ($sub->fetch()) {
|
||||||
try {
|
try {
|
||||||
|
$uri = Subscription::newUri(
|
||||||
|
$sub->getSubscriber(),
|
||||||
|
$sub->getSubscribed(),
|
||||||
|
$sub->created
|
||||||
|
);
|
||||||
$sub->decache();
|
$sub->decache();
|
||||||
$sub->query(sprintf(
|
$sub->query(sprintf(
|
||||||
'UPDATE subscription '.
|
<<<'END'
|
||||||
"SET uri = '%s' " .
|
UPDATE subscription
|
||||||
'WHERE subscriber = %d '.
|
SET uri = %1$s, modified = CURRENT_TIMESTAMP
|
||||||
'AND subscribed = %d',
|
WHERE subscriber = %2$d AND subscribed = %3$d
|
||||||
$sub->escape(Subscription::newUri($sub->getSubscriber(), $sub->getSubscribed(), $sub->created)),
|
END,
|
||||||
|
$sub->_quote($uri),
|
||||||
$sub->subscriber,
|
$sub->subscriber,
|
||||||
$sub->subscribed
|
$sub->subscribed
|
||||||
));
|
));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_log(LOG_ERR, "Error updated subscription URI: " . $e->getMessage());
|
common_log(LOG_ERR, 'Error updating subscription URI: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -429,13 +454,19 @@ function initGroupMemberURI()
|
||||||
if ($mem->find()) {
|
if ($mem->find()) {
|
||||||
while ($mem->fetch()) {
|
while ($mem->fetch()) {
|
||||||
try {
|
try {
|
||||||
|
$uri = Group_member::newUri(
|
||||||
|
Profile::getByID($mem->profile_id),
|
||||||
|
User_group::getByID($mem->group_id),
|
||||||
|
$mem->created
|
||||||
|
);
|
||||||
$mem->decache();
|
$mem->decache();
|
||||||
$mem->query(sprintf(
|
$mem->query(sprintf(
|
||||||
'UPDATE group_member '.
|
<<<'END'
|
||||||
"SET uri = '%s' " .
|
UPDATE group_member
|
||||||
'WHERE profile_id = %d ' .
|
SET uri = %s, modified = CURRENT_TIMESTAMP
|
||||||
'AND group_id = %d',
|
WHERE profile_id = %d AND group_id = %d
|
||||||
Group_member::newUri(Profile::getByID($mem->profile_id), User_group::getByID($mem->group_id), $mem->created),
|
END,
|
||||||
|
$mem->_quote($uri),
|
||||||
$mem->profile_id,
|
$mem->profile_id,
|
||||||
$mem->group_id
|
$mem->group_id
|
||||||
));
|
));
|
||||||
|
@ -643,7 +674,7 @@ function fixupFileThumbnailUrlhash()
|
||||||
$thumb = new File_thumbnail();
|
$thumb = new File_thumbnail();
|
||||||
$thumb->query(sprintf(
|
$thumb->query(sprintf(
|
||||||
'UPDATE %1$s ' .
|
'UPDATE %1$s ' .
|
||||||
'SET urlhash = %2$s ' .
|
'SET urlhash = %2$s, modified = CURRENT_TIMESTAMP ' .
|
||||||
'WHERE url IS NOT NULL ' . // find all entries with a url value
|
'WHERE url IS NOT NULL ' . // find all entries with a url value
|
||||||
"AND url <> '' " . // precaution against non-null empty strings
|
"AND url <> '' " . // precaution against non-null empty strings
|
||||||
'AND urlhash IS NULL', // but don't touch those we've already calculated
|
'AND urlhash IS NULL', // but don't touch those we've already calculated
|
||||||
|
|
Loading…
Reference in New Issue
Block a user