Add new PostUpdate function to initialize delivery data

This commit is contained in:
Hypolite Petovan 2019-01-23 00:02:00 -05:00
parent 7ff1b19cc0
commit 1ee1d7ef4e
1 changed files with 39 additions and 0 deletions

View File

@ -34,6 +34,9 @@ class PostUpdate
if (!self::update1281()) { if (!self::update1281()) {
return false; return false;
} }
if (!self::update1297()) {
return false;
}
return true; return true;
} }
@ -377,4 +380,40 @@ class PostUpdate
return false; return false;
} }
/**
* Set the delivery queue count to a negative value for all items preceding the feature.
*
* @return bool "true" when the job is done
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function update1297()
{
// Was the script completed?
if (Config::get('system', 'post_update_version') >= 1297) {
return true;
}
$max_item_delivery_data = DBA::selectFirst('item-delivery-data', ['iid'], ['queue_count > 0 OR queue_done > 0'], ['order' => ['iid']]);
$max_iid = $max_item_delivery_data['iid'];
Logger::info('Start update1297 with max iid: ' . $max_iid);
$condition = ['`queue_count` = 0 AND `iid` < ?', $max_iid];
DBA::update('item-delivery-data', ['queue_count' => -1], $condition);
if (DBA::errorNo() != 0) {
Logger::error('Database error ' . DBA::errorNo() . ':' . DBA::errorMessage());
return false;
}
Logger::info('Processed rows: ' . DBA::affectedRows());
Config::set('system', 'post_update_version', 1297);
Logger::info('Done');
return true;
}
} }