use Friendica\Core\Config;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
-use Friendica\Core\L10n;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\ItemURI;
+use Friendica\Model\UserItem;
use Friendica\Model\PermissionSet;
-use Friendica\Database\DBA;
/**
* Post update functions
if (!self::update1281()) {
return false;
}
+ if (!self::update1297()) {
+ return false;
+ }
+ if (!self::update1322()) {
+ return false;
+ }
+ if (!self::update1329()) {
+ return false;
+ }
return true;
}
* @brief Updates the "global" field in the item table
*
* @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function update1194()
{
* This field avoids cost intensive calls in the admin panel and in "nodeinfo"
*
* @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function update1206()
{
* @brief update the item related tables
*
* @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
*/
private static function update1279()
{
* @brief update item-uri data. Prerequisite for the next item structure update.
*
* @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function update1281()
{
return false;
}
- // Post-update script of PR 5596
- function fixGenderStrings() {
- $allGenders = DBA::select('contact', ['id', 'gender']);
- $allLangs = L10n::getAvailableLanguages();
- $success = 0;
- $fail = 0;
- foreach($allGenders as $key=>$gender) {
- foreach($allLangs as $key=>$lang) {
-
- $a = new \stdClass();
- $a->strings = [];
-
- // First we get the the localizations
- if (file_exists("view/lang/$lang/strings.php")) {
- include "view/lang/$lang/strings.php";
- }
- if (file_exists("addon/morechoice/lang/$lang/strings.php")) {
- include "addon/morechoice/lang/$lang/strings.php";
- }
-
- $localizedStrings = $a->strings;
- unset($a);
-
- $key = array_search($gender['gender'], $localizedStrings);
- if($key !== false) {
- break;
- }
-
- // defaulting to empty string
- $key = '';
- }
- DBA::update('contact', ['gender' => $key], ['id' => $gender['id']]);
- logger::log('Updated contact ' . $gender['id'] . ' to gender ' . $key . ' (was: ' . $gender['gender'] . ')');
-
- if ($key == '') {
- $fail++;
- }
- else {
- $success++;
- }
- }
-
- Logger::log("Gender fix completed. Success: $success. Fail: $fail");
- }
+ /**
+ * 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;
+ }
+ /**
+ * Remove contact duplicates
+ *
+ * @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ private static function update1322()
+ {
+ // Was the script completed?
+ if (Config::get('system', 'post_update_version') >= 1322) {
+ return true;
+ }
+
+ Logger::info('Start');
+
+ $contacts = DBA::p("SELECT `nurl`, `uid` FROM `contact`
+ WHERE EXISTS (SELECT `nurl` FROM `contact` AS `c2`
+ WHERE `c2`.`nurl` = `contact`.`nurl` AND `c2`.`id` != `contact`.`id` AND `c2`.`uid` = `contact`.`uid` AND `c2`.`network` IN (?, ?, ?) AND NOT `deleted`)
+ AND (`network` IN (?, ?, ?) OR (`uid` = ?)) AND NOT `deleted` GROUP BY `nurl`, `uid`",
+ Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB,
+ Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB, 0);
+
+ while ($contact = DBA::fetch($contacts)) {
+ Logger::info('Remove duplicates', ['nurl' => $contact['nurl'], 'uid' => $contact['uid']]);
+ Contact::removeDuplicates($contact['nurl'], $contact['uid']);
+ }
+
+ DBA::close($contact);
+ Config::set('system', 'post_update_version', 1322);
+
+ Logger::info('Done');
+
+ return true;
+ }
+
+ /**
+ * @brief update user-item data with notifications
+ *
+ * @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ private static function update1329()
+ {
+ // Was the script completed?
+ if (Config::get('system', 'post_update_version') >= 1329) {
+ return true;
+ }
+
+ $id = Config::get('system', 'post_update_version_1329_id', 0);
+
+ Logger::info('Start', ['item' => $id]);
+
+ $start_id = $id;
+ $rows = 0;
+ $condition = ["`id` > ?", $id];
+ $params = ['order' => ['id'], 'limit' => 10000];
+ $items = DBA::select('item', ['id'], $condition, $params);
+
+ if (DBA::errorNo() != 0) {
+ Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+ return false;
+ }
+
+ while ($item = DBA::fetch($items)) {
+ $id = $item['id'];
+
+ UserItem::setNotification($item['id']);
+
+ ++$rows;
+ }
+ DBA::close($items);
+
+ Config::set('system', 'post_update_version_1329_id', $id);
+
+ Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
+
+ if ($start_id == $id) {
+ Config::set('system', 'post_update_version', 1329);
+ Logger::info('Done');
+ return true;
+ }
+
+ return false;
+ }
}