+ if ($start_id == $id) {
+ DI::config()->set("system", "post_update_version", 1348);
+ Logger::info('Done');
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * update the "gsid" (global server id) field in the apcontact table
+ *
+ * @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function update1349()
+ {
+ // Was the script completed?
+ if (DI::config()->get("system", "post_update_version") >= 1349) {
+ return true;
+ }
+
+ $id = DI::config()->get("system", "post_update_version_1349_id", '');
+
+ Logger::info('Start', ['apcontact' => $id]);
+
+ $start_id = $id;
+ $rows = 0;
+ $condition = ["`url` > ? AND `gsid` IS NULL AND `baseurl` != '' AND NOT `baseurl` IS NULL", $id];
+ $params = ['order' => ['url'], 'limit' => 10000];
+ $apcontacts = DBA::select('apcontact', ['url', 'baseurl'], $condition, $params);
+
+ if (DBA::errorNo() != 0) {
+ Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+ return false;
+ }
+
+ while ($apcontact = DBA::fetch($apcontacts)) {
+ $id = $apcontact['url'];
+
+ DBA::update('apcontact',
+ ['gsid' => GServer::getID($apcontact['baseurl'], true), 'baseurl' => GServer::cleanURL($apcontact['baseurl'])],
+ ['url' => $apcontact['url']]);
+
+ ++$rows;
+ }
+ DBA::close($apcontacts);
+
+ DI::config()->set("system", "post_update_version_1349_id", $id);
+
+ Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
+
+ if ($start_id == $id) {
+ DI::config()->set("system", "post_update_version", 1349);
+ Logger::info('Done');
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Remove orphaned photo entries
+ *
+ * @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function update1383()
+ {
+ // Was the script completed?
+ if (DI::config()->get("system", "post_update_version") >= 1383) {
+ return true;
+ }
+
+ Logger::info('Start');
+
+ $deleted = 0;
+ $avatar = [4 => 'photo', 5 => 'thumb', 6 => 'micro'];
+
+ $photos = DBA::select('photo', ['id', 'contact-id', 'resource-id', 'scale'], ["`contact-id` != ? AND `album` = ?", 0, Photo::CONTACT_PHOTOS]);
+ while ($photo = DBA::fetch($photos)) {
+ $delete = !in_array($photo['scale'], [4, 5, 6]);
+
+ if (!$delete) {
+ // Check if there is a contact entry with that photo
+ $delete = !DBA::exists('contact', ["`id` = ? AND `" . $avatar[$photo['scale']] . "` LIKE ?",
+ $photo['contact-id'], '%' . $photo['resource-id'] . '%']);