+ Logger::log("Done", Logger::DEBUG);
+ return true;
+ }
+
+ return false;
+ }
+
+ private static function createLanguage(&$item)
+ {
+ if (empty($item['postopts'])) {
+ return;
+ }
+
+ $opts = explode(',', $item['postopts']);
+
+ $postopts = [];
+
+ foreach ($opts as $opt) {
+ if (strstr($opt, 'lang=')) {
+ $language = substr($opt, 5);
+ } else {
+ $postopts[] = $opt;
+ }
+ }
+
+ if (empty($language)) {
+ return;
+ }
+
+ if (!empty($postopts)) {
+ $item['postopts'] = implode(',', $postopts);
+ } else {
+ $item['postopts'] = null;
+ }
+
+ $lang_pairs = explode(':', $language);
+
+ $lang_arr = [];
+
+ foreach ($lang_pairs as $pair) {
+ $lang_pair_arr = explode(';', $pair);
+ if (count($lang_pair_arr) == 2) {
+ $lang_arr[$lang_pair_arr[0]] = $lang_pair_arr[1];
+ }
+ }
+
+ $item['language'] = json_encode($lang_arr);
+ }
+
+ /**
+ * @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()
+ {
+ // Was the script completed?
+ if (Config::get("system", "post_update_version") >= 1281) {
+ return true;
+ }
+
+ $id = Config::get("system", "post_update_version_1281_id", 0);
+
+ Logger::log("Start from item " . $id, Logger::DEBUG);
+
+ $fields = ['id', 'guid', 'uri', 'uri-id', 'parent-uri', 'parent-uri-id', 'thr-parent', 'thr-parent-id'];
+
+ $start_id = $id;
+ $rows = 0;
+ $condition = ["`id` > ?", $id];
+ $params = ['order' => ['id'], 'limit' => 10000];
+ $items = DBA::select('item', $fields, $condition, $params);
+
+ if (DBA::errorNo() != 0) {
+ Logger::log('Database error ' . DBA::errorNo() . ':' . DBA::errorMessage());
+ return false;
+ }
+
+ while ($item = DBA::fetch($items)) {
+ $id = $item['id'];
+
+ if (empty($item['uri'])) {
+ // Should not happen
+ continue;
+ } elseif (empty($item['uri-id'])) {
+ $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
+ }
+
+ if (empty($item['parent-uri'])) {
+ $item['parent-uri-id'] = $item['uri-id'];
+ } elseif (empty($item['parent-uri-id'])) {
+ $item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
+ }
+
+ // Very old items don't have this field
+ if (empty($item['thr-parent'])) {
+ $item['thr-parent-id'] = $item['parent-uri-id'];
+ } elseif (empty($item['thr-parent-id'])) {
+ $item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
+ }
+
+ unset($item['id']);
+ unset($item['guid']);
+ unset($item['uri']);
+ unset($item['parent-uri']);
+ unset($item['thr-parent']);
+
+ DBA::update('item', $item, ['id' => $id]);
+
+ ++$rows;
+ }
+ DBA::close($items);
+
+ Config::set("system", "post_update_version_1281_id", $id);
+
+ Logger::log("Processed rows: " . $rows . " - last processed item: " . $id, Logger::DEBUG);
+
+ if ($start_id == $id) {
+ Logger::log("Updating item-uri in item-activity", Logger::DEBUG);
+ DBA::e("UPDATE `item-activity` INNER JOIN `item-uri` ON `item-uri`.`uri` = `item-activity`.`uri` SET `item-activity`.`uri-id` = `item-uri`.`id` WHERE `item-activity`.`uri-id` IS NULL");
+
+ Logger::log("Updating item-uri in item-content", Logger::DEBUG);
+ DBA::e("UPDATE `item-content` INNER JOIN `item-uri` ON `item-uri`.`uri` = `item-content`.`uri` SET `item-content`.`uri-id` = `item-uri`.`id` WHERE `item-content`.`uri-id` IS NULL");
+
+ Config::set("system", "post_update_version", 1281);
+ Logger::log("Done", Logger::DEBUG);