Next item structure works (#5380)

* Use "LEFT JOIN" to always fetch the item. Needed for update routines.

* New conversion routine that now covers every item

* Post update is now activated

* We now use a hash based upon RIPEMD-320 for content and activity

* The hash doesn't contain the plink anymore

* Legacy item fields are now "null"able

* New hash function for a server unique item hash

* Introduction of the legacy mode (usage of old item fields)

* Code simplification

* We don't need the "uri" fields anymore in item-activity and item-content

* Use the "created" and not the "received" date for the hash

* Avoiding several notices

* Some more warnings removed

* Improved uri-hash / Likes on Diaspora are now getting a creation date

* Corrected the post update version

* Ensure an unique uri-hash

* Don't delete orhaned item data at the moment

* Partly reworked, due to strange behaviour

* Some more parts reworked

* Using the uri currently seems to be more reliable

* Using the uri here as well

* Use the hash values again

* Grouped item fields in different categories

* Notices again

* use the gravity (we always should)

* Added hint for disabled post updates

* Notices ...

* Issue #5337: Personal notes are displayed again

* Use the gravity again
This commit is contained in:
Michael Vogel 2018-07-15 20:36:20 +02:00 committed by Hypolite Petovan
parent 8ad6b65aeb
commit d3a2ed85fe
21 changed files with 315 additions and 297 deletions

View file

@ -31,10 +31,7 @@ class PostUpdate
if (!self::update1206()) {
return;
}
if (!self::update1274()) {
return;
}
if (!self::update1275()) {
if (!self::update1276()) {
return;
}
}
@ -226,95 +223,62 @@ class PostUpdate
}
/**
* @brief update the "item-content" table
* @brief update the item related tables
*
* @return bool "true" when the job is done
*/
private static function update1274()
private static function update1276()
{
// Was the script completed?
if (Config::get("system", "post_update_version") >= 1274) {
if (Config::get("system", "post_update_version") >= 1276) {
return true;
}
logger("Start", LOGGER_DEBUG);
$id = Config::get("system", "post_update_version_1276_id", 0);
$fields = ['id', 'title', 'content-warning', 'body', 'location', 'tag', 'file',
'coord', 'app', 'rendered-hash', 'rendered-html', 'verb',
'object-type', 'object', 'target-type', 'target', 'plink',
'author-id', 'owner-id'];
logger("Start from item " . $id, LOGGER_DEBUG);
$condition = ["`icid` IS NULL"];
$params = ['limit' => 10000];
$items = Item::select($fields, $condition, $params);
if (!DBM::is_result($items)) {
Config::set("system", "post_update_version", 1274);
logger("Done", LOGGER_DEBUG);
return true;
}
$fields = array_merge(Item::MIXED_CONTENT_FIELDLIST, ['network', 'author-id', 'owner-id', 'tag', 'file',
'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'id']);
$start_id = $id;
$rows = 0;
$condition = ["`id` > ?", $id];
$params = ['order' => ['id'], 'limit' => 10000];
$items = Item::select($fields, $condition, $params);
while ($item = Item::fetch($items)) {
// Clearing the author and owner data if there is an id.
if ($item['author-id'] > 0) {
$item['author-name'] = '';
$item['author-link'] = '';
$item['author-avatar'] = '';
$id = $item['id'];
if (empty($item['author-id'])) {
$default = ['url' => $item['author-link'], 'name' => $item['author-name'],
'photo' => $item['author-avatar'], 'network' => $item['network']];
$item['author-id'] = Contact::getIdForURL($item["author-link"], 0, false, $default);
}
if ($item['owner-id'] > 0) {
$item['owner-name'] = '';
$item['owner-link'] = '';
$item['owner-avatar'] = '';
if (empty($item['owner-id'])) {
$default = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
'photo' => $item['owner-avatar'], 'network' => $item['network']];
$item['owner-id'] = Contact::getIdForURL($item["owner-link"], 0, false, $default);
}
Item::update($item, ['id' => $item['id']]);
Item::update($item, ['id' => $id]);
++$rows;
}
dba::close($items);
logger("Processed rows: " . $rows, LOGGER_DEBUG);
return true;
}
/**
* @brief update the "item-activity" table
*
* @return bool "true" when the job is done
*/
private static function update1275()
{
// Was the script completed?
if (Config::get("system", "post_update_version") >= 1275) {
return true;
}
Config::set("system", "post_update_version_1276_id", $id);
logger("Start", LOGGER_DEBUG);
logger("Processed rows: " . $rows . " - last processed item: " . $id, LOGGER_DEBUG);
$fields = ['id', 'verb'];
$condition = ["`iaid` IS NULL AND NOT `icid` IS NULL AND `verb` IN (?, ?, ?, ?, ?)",
ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE];
$params = ['limit' => 10000];
$items = Item::select($fields, $condition, $params);
if (!DBM::is_result($items)) {
Config::set("system", "post_update_version", 1275);
if ($start_id == $id) {
Config::set("system", "post_update_version", 1276);
logger("Done", LOGGER_DEBUG);
return true;
}
$rows = 0;
while ($item = Item::fetch($items)) {
Item::update($item, ['id' => $item['id']]);
++$rows;
}
dba::close($items);
logger("Processed rows: " . $rows, LOGGER_DEBUG);
return true;
return false;
}
}