Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

751 lines
22 KiB

  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2020, Friendica
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * Automatic post-databse structure change updates
  21. *
  22. * These functions are responsible for doing critical post update changes to the data (not the structure) in the database.
  23. *
  24. * Database structure changes are done in static/dbstructure.config.php
  25. *
  26. * For non-critical database migrations, please add a method in the Database\PostUpdate class
  27. *
  28. * If there is a need for a post update to a structure change, update this file
  29. * by adding a new function at the end with the number of the new DB_UPDATE_VERSION.
  30. *
  31. * The numbered script in this file has to be exactly like the DB_UPDATE_VERSION
  32. *
  33. * Example:
  34. * You are currently on version 4711 and you are preparing changes that demand an update script.
  35. *
  36. * 1. Create a function "update_4712()" here in the update.php
  37. * 2. Apply the needed structural changes in static/dbStructure.php
  38. * 3. Set DB_UPDATE_VERSION in static/dbstructure.config.php to 4712.
  39. *
  40. * If you need to run a script before the database update, name the function "pre_update_4712()"
  41. */
  42. use Friendica\Core\Addon;
  43. use Friendica\Core\Logger;
  44. use Friendica\Core\Update;
  45. use Friendica\Core\Worker;
  46. use Friendica\Database\DBA;
  47. use Friendica\Database\DBStructure;
  48. use Friendica\DI;
  49. use Friendica\Model\Contact;
  50. use Friendica\Model\Item;
  51. use Friendica\Model\Photo;
  52. use Friendica\Model\User;
  53. use Friendica\Model\Storage;
  54. use Friendica\Util\DateTimeFormat;
  55. use Friendica\Worker\Delivery;
  56. function update_1179()
  57. {
  58. if (DI::config()->get('system', 'no_community_page')) {
  59. DI::config()->set('system', 'community_page_style', CP_NO_COMMUNITY_PAGE);
  60. }
  61. // Update the central item storage with uid=0
  62. Worker::add(PRIORITY_LOW, "threadupdate");
  63. return Update::SUCCESS;
  64. }
  65. function update_1181()
  66. {
  67. // Fill the new fields in the term table.
  68. // deactivated, the "term" table is deprecated
  69. // Worker::add(PRIORITY_LOW, "TagUpdate");
  70. return Update::SUCCESS;
  71. }
  72. function update_1189()
  73. {
  74. if (strlen(DI::config()->get('system', 'directory_submit_url')) &&
  75. !strlen(DI::config()->get('system', 'directory'))) {
  76. DI::config()->set('system', 'directory', dirname(DI::config()->get('system', 'directory_submit_url')));
  77. DI::config()->delete('system', 'directory_submit_url');
  78. }
  79. return Update::SUCCESS;
  80. }
  81. function update_1191()
  82. {
  83. DI::config()->set('system', 'maintenance', 1);
  84. if (Addon::isEnabled('forumlist')) {
  85. Addon::uninstall('forumlist');
  86. }
  87. // select old formlist addon entries
  88. $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ",
  89. DBA::escape('forumlist')
  90. );
  91. // convert old forumlist addon entries in new config entries
  92. if (DBA::isResult($r)) {
  93. foreach ($r as $rr) {
  94. $uid = $rr['uid'];
  95. $family = $rr['cat'];
  96. $key = $rr['k'];
  97. $value = $rr['v'];
  98. if ($key === 'randomise') {
  99. DI::pConfig()->delete($uid, $family, $key);
  100. }
  101. if ($key === 'show_on_profile') {
  102. if ($value) {
  103. DI::pConfig()->set($uid, 'feature', 'forumlist_profile', $value);
  104. }
  105. DI::pConfig()->delete($uid, $family, $key);
  106. }
  107. if ($key === 'show_on_network') {
  108. if ($value) {
  109. DI::pConfig()->set($uid, 'feature', 'forumlist_widget', $value);
  110. }
  111. DI::pConfig()->delete($uid, $family, $key);
  112. }
  113. }
  114. }
  115. DI::config()->set('system', 'maintenance', 0);
  116. return Update::SUCCESS;
  117. }
  118. function update_1203()
  119. {
  120. $r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)",
  121. DBA::escape(User::ACCOUNT_TYPE_COMMUNITY),
  122. DBA::escape(User::PAGE_FLAGS_COMMUNITY),
  123. DBA::escape(User::PAGE_FLAGS_PRVGROUP)
  124. );
  125. }
  126. function update_1244()
  127. {
  128. // Sets legacy_password for all legacy hashes
  129. DBA::update('user', ['legacy_password' => true], ['SUBSTR(password, 1, 4) != "$2y$"']);
  130. // All legacy hashes are re-hashed using the new secure hashing function
  131. $stmt = DBA::select('user', ['uid', 'password'], ['legacy_password' => true]);
  132. while ($user = DBA::fetch($stmt)) {
  133. DBA::update('user', ['password' => User::hashPassword($user['password'])], ['uid' => $user['uid']]);
  134. }
  135. // Logged in users are forcibly logged out
  136. DBA::delete('session', ['1 = 1']);
  137. return Update::SUCCESS;
  138. }
  139. function update_1245()
  140. {
  141. $rino = DI::config()->get('system', 'rino_encrypt');
  142. if (!$rino) {
  143. return Update::SUCCESS;
  144. }
  145. DI::config()->set('system', 'rino_encrypt', 1);
  146. return Update::SUCCESS;
  147. }
  148. function update_1247()
  149. {
  150. // Removing hooks with the old name
  151. DBA::e("DELETE FROM `hook`
  152. WHERE `hook` LIKE 'plugin_%'");
  153. // Make sure we install the new renamed ones
  154. Addon::reload();
  155. }
  156. function update_1260()
  157. {
  158. DI::config()->set('system', 'maintenance', 1);
  159. DI::config()->set(
  160. 'system',
  161. 'maintenance_reason',
  162. DI::l10n()->t(
  163. '%s: Updating author-id and owner-id in item and thread table. ',
  164. DateTimeFormat::utcNow().' '.date('e')
  165. )
  166. );
  167. $items = DBA::p("SELECT `id`, `owner-link`, `owner-name`, `owner-avatar`, `network` FROM `item`
  168. WHERE `owner-id` = 0 AND `owner-link` != ''");
  169. while ($item = DBA::fetch($items)) {
  170. $contact = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
  171. 'photo' => $item['owner-avatar'], 'network' => $item['network']];
  172. $cid = Contact::getIdForURL($item['owner-link'], 0, null, $contact);
  173. if (empty($cid)) {
  174. continue;
  175. }
  176. Item::update(['owner-id' => $cid], ['id' => $item['id']]);
  177. }
  178. DBA::close($items);
  179. DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
  180. SET `thread`.`owner-id` = `item`.`owner-id` WHERE `thread`.`owner-id` = 0");
  181. $items = DBA::p("SELECT `id`, `author-link`, `author-name`, `author-avatar`, `network` FROM `item`
  182. WHERE `author-id` = 0 AND `author-link` != ''");
  183. while ($item = DBA::fetch($items)) {
  184. $contact = ['url' => $item['author-link'], 'name' => $item['author-name'],
  185. 'photo' => $item['author-avatar'], 'network' => $item['network']];
  186. $cid = Contact::getIdForURL($item['author-link'], 0, null, $contact);
  187. if (empty($cid)) {
  188. continue;
  189. }
  190. Item::update(['author-id' => $cid], ['id' => $item['id']]);
  191. }
  192. DBA::close($items);
  193. DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
  194. SET `thread`.`author-id` = `item`.`author-id` WHERE `thread`.`author-id` = 0");
  195. DI::config()->set('system', 'maintenance', 0);
  196. return Update::SUCCESS;
  197. }
  198. function update_1261()
  199. {
  200. // This fixes the results of an issue in the develop branch of 2018-05.
  201. DBA::update('contact', ['blocked' => false, 'pending' => false], ['uid' => 0, 'blocked' => true, 'pending' => true]);
  202. return Update::SUCCESS;
  203. }
  204. function update_1278()
  205. {
  206. DI::config()->set('system', 'maintenance', 1);
  207. DI::config()->set(
  208. 'system',
  209. 'maintenance_reason',
  210. DI::l10n()->t(
  211. '%s: Updating post-type.',
  212. DateTimeFormat::utcNow().' '.date('e')
  213. )
  214. );
  215. Item::update(['post-type' => Item::PT_PAGE], ['bookmark' => true]);
  216. Item::update(['post-type' => Item::PT_PERSONAL_NOTE], ['type' => 'note']);
  217. DI::config()->set('system', 'maintenance', 0);
  218. return Update::SUCCESS;
  219. }
  220. function update_1288()
  221. {
  222. // Updates missing `uri-id` values
  223. DBA::e("UPDATE `item-activity` INNER JOIN `item` ON `item`.`iaid` = `item-activity`.`id` SET `item-activity`.`uri-id` = `item`.`uri-id` WHERE `item-activity`.`uri-id` IS NULL OR `item-activity`.`uri-id` = 0");
  224. DBA::e("UPDATE `item-content` INNER JOIN `item` ON `item`.`icid` = `item-content`.`id` SET `item-content`.`uri-id` = `item`.`uri-id` WHERE `item-content`.`uri-id` IS NULL OR `item-content`.`uri-id` = 0");
  225. return Update::SUCCESS;
  226. }
  227. // Post-update script of PR 5751
  228. function update_1298()
  229. {
  230. $keys = ['gender', 'marital', 'sexual'];
  231. foreach ($keys as $translateKey) {
  232. $allData = DBA::select('profile', ['id', $translateKey]);
  233. $allLangs = DI::l10n()->getAvailableLanguages();
  234. $success = 0;
  235. $fail = 0;
  236. foreach ($allData as $key => $data) {
  237. $toTranslate = $data[$translateKey];
  238. if ($toTranslate != '') {
  239. foreach ($allLangs as $key => $lang) {
  240. $a = new \stdClass();
  241. $a->strings = [];
  242. // First we get the the localizations
  243. if (file_exists("view/lang/$lang/strings.php")) {
  244. include "view/lang/$lang/strings.php";
  245. }
  246. if (file_exists("addon/morechoice/lang/$lang/strings.php")) {
  247. include "addon/morechoice/lang/$lang/strings.php";
  248. }
  249. $localizedStrings = $a->strings;
  250. unset($a);
  251. $key = array_search($toTranslate, $localizedStrings);
  252. if ($key !== false) {
  253. break;
  254. }
  255. // defaulting to empty string
  256. $key = '';
  257. }
  258. if ($key == '') {
  259. $fail++;
  260. } else {
  261. DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
  262. Logger::notice('Updated contact', ['action' => 'update', 'contact' => $data['id'], "$translateKey" => $key,
  263. 'was' => $data[$translateKey]]);
  264. Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
  265. Contact::updateSelfFromUserID($data['id']);
  266. $success++;
  267. }
  268. }
  269. }
  270. Logger::notice($translateKey . " fix completed", ['action' => 'update', 'translateKey' => $translateKey, 'Success' => $success, 'Fail' => $fail ]);
  271. }
  272. return Update::SUCCESS;
  273. }
  274. function update_1309()
  275. {
  276. $queue = DBA::select('queue', ['id', 'cid', 'guid']);
  277. while ($entry = DBA::fetch($queue)) {
  278. $contact = DBA::selectFirst('contact', ['uid'], ['id' => $entry['cid']]);
  279. if (!DBA::isResult($contact)) {
  280. continue;
  281. }
  282. $item = Item::selectFirst(['id', 'gravity'], ['uid' => $contact['uid'], 'guid' => $entry['guid']]);
  283. if (!DBA::isResult($item)) {
  284. continue;
  285. }
  286. $deliver_options = ['priority' => PRIORITY_MEDIUM, 'dont_fork' => true];
  287. Worker::add($deliver_options, 'Delivery', Delivery::POST, $item['id'], $entry['cid']);
  288. Logger::info('Added delivery worker', ['item' => $item['id'], 'contact' => $entry['cid']]);
  289. DBA::delete('queue', ['id' => $entry['id']]);
  290. }
  291. return Update::SUCCESS;
  292. }
  293. function update_1315()
  294. {
  295. if (DBStructure::existsTable('item-delivery-data')) {
  296. DBA::delete('item-delivery-data', ['postopts' => '', 'inform' => '', 'queue_count' => 0, 'queue_done' => 0]);
  297. }
  298. return Update::SUCCESS;
  299. }
  300. function update_1318()
  301. {
  302. DBA::update('profile', ['marital' => "In a relation"], ['marital' => "Unavailable"]);
  303. DBA::update('profile', ['marital' => "Single"], ['marital' => "Available"]);
  304. Worker::add(PRIORITY_LOW, 'ProfileUpdate');
  305. return Update::SUCCESS;
  306. }
  307. function update_1323()
  308. {
  309. $users = DBA::select('user', ['uid']);
  310. while ($user = DBA::fetch($users)) {
  311. Contact::updateSelfFromUserID($user['uid']);
  312. }
  313. DBA::close($users);
  314. return Update::SUCCESS;
  315. }
  316. function update_1327()
  317. {
  318. $contacts = DBA::select('contact', ['uid', 'id', 'blocked', 'readonly'], ["`uid` != ? AND (`blocked` OR `readonly`) AND NOT `pending`", 0]);
  319. while ($contact = DBA::fetch($contacts)) {
  320. Contact\User::setBlocked($contact['id'], $contact['uid'], $contact['blocked']);
  321. Contact\User::setIgnored($contact['id'], $contact['uid'], $contact['readonly']);
  322. }
  323. DBA::close($contacts);
  324. return Update::SUCCESS;
  325. }
  326. function update_1330()
  327. {
  328. $currStorage = DI::config()->get('storage', 'class', '');
  329. // set the name of the storage instead of the classpath as config
  330. if (!empty($currStorage)) {
  331. /** @var Storage\IStorage $currStorage */
  332. if (!DI::config()->set('storage', 'name', $currStorage::getName())) {
  333. return Update::FAILED;
  334. }
  335. // try to delete the class since it isn't needed. This won't work with config files
  336. DI::config()->delete('storage', 'class');
  337. }
  338. // Update attachments and photos
  339. if (!DBA::p("UPDATE `photo` SET `photo`.`backend-class` = SUBSTR(`photo`.`backend-class`, 25) WHERE `photo`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'") ||
  340. !DBA::p("UPDATE `attach` SET `attach`.`backend-class` = SUBSTR(`attach`.`backend-class`, 25) WHERE `attach`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'")) {
  341. return Update::FAILED;
  342. };
  343. return Update::SUCCESS;
  344. }
  345. function update_1332()
  346. {
  347. $condition = ["`is-default` IS NOT NULL"];
  348. $profiles = DBA::select('profile', [], $condition);
  349. while ($profile = DBA::fetch($profiles)) {
  350. DI::profileField()->migrateFromLegacyProfile($profile);
  351. }
  352. DBA::close($profiles);
  353. DBA::update('contact', ['profile-id' => null], ['`profile-id` IS NOT NULL']);
  354. return Update::SUCCESS;
  355. }
  356. function update_1347()
  357. {
  358. foreach (Item::ACTIVITIES as $index => $activity) {
  359. DBA::insert('verb', ['id' => $index + 1, 'name' => $activity], true);
  360. }
  361. return Update::SUCCESS;
  362. }
  363. function pre_update_1348()
  364. {
  365. if (!DBA::exists('contact', ['id' => 0])) {
  366. DBA::insert('contact', ['nurl' => '']);
  367. $lastid = DBA::lastInsertId();
  368. if ($lastid != 0) {
  369. DBA::update('contact', ['id' => 0], ['id' => $lastid]);
  370. }
  371. }
  372. // The tables "permissionset" and "tag" could or could not exist during the update.
  373. // This depends upon the previous version. Depending upon this situation we have to add
  374. // the "0" values before adding the foreign keys - or after would be sufficient.
  375. update_1348();
  376. DBA::e("DELETE FROM `auth_codes` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)");
  377. DBA::e("DELETE FROM `tokens` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)");
  378. return Update::SUCCESS;
  379. }
  380. function update_1348()
  381. {
  382. // Insert a permissionset with id=0
  383. // Inserting it without an ID and then changing the value to 0 tricks the auto increment
  384. if (!DBA::exists('permissionset', ['id' => 0])) {
  385. DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);
  386. $lastid = DBA::lastInsertId();
  387. if ($lastid != 0) {
  388. DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
  389. }
  390. }
  391. if (!DBA::exists('tag', ['id' => 0])) {
  392. DBA::insert('tag', ['name' => '']);
  393. $lastid = DBA::lastInsertId();
  394. if ($lastid != 0) {
  395. DBA::update('tag', ['id' => 0], ['id' => $lastid]);
  396. }
  397. }
  398. return Update::SUCCESS;
  399. }
  400. function update_1349()
  401. {
  402. $correct = true;
  403. foreach (Item::ACTIVITIES as $index => $activity) {
  404. if (!DBA::exists('verb', ['id' => $index + 1, 'name' => $activity])) {
  405. $correct = false;
  406. }
  407. }
  408. if (!$correct) {
  409. // The update failed - but it cannot be recovered, since the data doesn't match our expectation
  410. // This means that we can't use this "shortcut" to fill the "vid" field and we have to rely upon
  411. // the postupdate. This is not fatal, but means that it will take some longer time for the system
  412. // to fill all data.
  413. return Update::SUCCESS;
  414. }
  415. if (!DBA::e("UPDATE `item` INNER JOIN `item-activity` ON `item`.`uri-id` = `item-activity`.`uri-id`
  416. SET `vid` = `item-activity`.`activity` + 1 WHERE `gravity` = ? AND (`vid` IS NULL OR `vid` = 0)", GRAVITY_ACTIVITY)) {
  417. return Update::FAILED;
  418. }
  419. return Update::SUCCESS;
  420. }
  421. function update_1351()
  422. {
  423. if (!DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id` SET `thread`.`uri-id` = `item`.`uri-id`")) {
  424. return Update::FAILED;
  425. }
  426. return Update::SUCCESS;
  427. }
  428. function pre_update_1354()
  429. {
  430. if (DBStructure::existsColumn('contact', ['ffi_keyword_blacklist'])
  431. && !DBStructure::existsColumn('contact', ['ffi_keyword_denylist'])
  432. && !DBA::e("ALTER TABLE `contact` CHANGE `ffi_keyword_blacklist` `ffi_keyword_denylist` text null")) {
  433. return Update::FAILED;
  434. }
  435. return Update::SUCCESS;
  436. }
  437. function update_1354()
  438. {
  439. if (DBStructure::existsColumn('contact', ['ffi_keyword_blacklist'])
  440. && DBStructure::existsColumn('contact', ['ffi_keyword_denylist'])) {
  441. if (!DBA::e("UPDATE `contact` SET `ffi_keyword_denylist` = `ffi_keyword_blacklist`")) {
  442. return Update::FAILED;
  443. }
  444. // When the data had been copied then the main task is done.
  445. // Having the old field removed is only beauty but not crucial.
  446. // So we don't care if this was successful or not.
  447. DBA::e("ALTER TABLE `contact` DROP `ffi_keyword_blacklist`");
  448. }
  449. return Update::SUCCESS;
  450. }
  451. function update_1357()
  452. {
  453. if (!DBA::e("UPDATE `contact` SET `failed` = true WHERE `success_update` < `failure_update` AND `failed` IS NULL")) {
  454. return Update::FAILED;
  455. }
  456. if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `success_update` > `failure_update` AND `failed` IS NULL")) {
  457. return Update::FAILED;
  458. }
  459. if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `updated` > `failure_update` AND `failed` IS NULL")) {
  460. return Update::FAILED;
  461. }
  462. if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `last-item` > `failure_update` AND `failed` IS NULL")) {
  463. return Update::FAILED;
  464. }
  465. if (!DBA::e("UPDATE `gserver` SET `failed` = true WHERE `last_contact` < `last_failure` AND `failed` IS NULL")) {
  466. return Update::FAILED;
  467. }
  468. if (!DBA::e("UPDATE `gserver` SET `failed` = false WHERE `last_contact` > `last_failure` AND `failed` IS NULL")) {
  469. return Update::FAILED;
  470. }
  471. return Update::SUCCESS;
  472. }
  473. function pre_update_1358()
  474. {
  475. if (!DBA::e("DELETE FROM `contact-relation` WHERE NOT `relation-cid` IN (SELECT `id` FROM `contact`) OR NOT `cid` IN (SELECT `id` FROM `contact`)")) {
  476. return Update::FAILED;
  477. }
  478. return Update::SUCCESS;
  479. }
  480. function pre_update_1363()
  481. {
  482. Photo::delete(["`contact-id` != ? AND NOT `contact-id` IN (SELECT `id` FROM `contact`)", 0]);
  483. return Update::SUCCESS;
  484. }
  485. function pre_update_1364()
  486. {
  487. if (!DBA::e("DELETE FROM `2fa_recovery_codes` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  488. return Update::FAILED;
  489. }
  490. if (!DBA::e("DELETE FROM `2fa_app_specific_password` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  491. return Update::FAILED;
  492. }
  493. if (!DBA::e("DELETE FROM `attach` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  494. return Update::FAILED;
  495. }
  496. if (!DBA::e("DELETE FROM `clients` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  497. return Update::FAILED;
  498. }
  499. if (!DBA::e("DELETE FROM `conv` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  500. return Update::FAILED;
  501. }
  502. if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  503. return Update::FAILED;
  504. }
  505. if (!DBA::e("DELETE FROM `group` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  506. return Update::FAILED;
  507. }
  508. if (!DBA::e("DELETE FROM `intro` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  509. return Update::FAILED;
  510. }
  511. if (!DBA::e("DELETE FROM `manage` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  512. return Update::FAILED;
  513. }
  514. if (!DBA::e("DELETE FROM `manage` WHERE NOT `mid` IN (SELECT `uid` FROM `user`)")) {
  515. return Update::FAILED;
  516. }
  517. if (!DBA::e("DELETE FROM `mail` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  518. return Update::FAILED;
  519. }
  520. if (!DBA::e("DELETE FROM `mailacct` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  521. return Update::FAILED;
  522. }
  523. if (!DBA::e("DELETE FROM `notify` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  524. return Update::FAILED;
  525. }
  526. if (!DBA::e("DELETE FROM `openwebauth-token` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  527. return Update::FAILED;
  528. }
  529. if (!DBA::e("DELETE FROM `pconfig` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  530. return Update::FAILED;
  531. }
  532. if (!DBA::e("DELETE FROM `profile` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  533. return Update::FAILED;
  534. }
  535. if (!DBA::e("DELETE FROM `profile_check` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  536. return Update::FAILED;
  537. }
  538. if (!DBA::e("DELETE FROM `profile_field` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  539. return Update::FAILED;
  540. }
  541. if (!DBA::e("DELETE FROM `push_subscriber` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  542. return Update::FAILED;
  543. }
  544. if (!DBA::e("DELETE FROM `register` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  545. return Update::FAILED;
  546. }
  547. if (!DBA::e("DELETE FROM `search` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  548. return Update::FAILED;
  549. }
  550. if (!DBA::e("DELETE FROM `tokens` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  551. return Update::FAILED;
  552. }
  553. if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  554. return Update::FAILED;
  555. }
  556. if (!DBA::e("DELETE FROM `user-item` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
  557. return Update::FAILED;
  558. }
  559. if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `receiver-uid` IN (SELECT `uid` FROM `user`)")) {
  560. return Update::FAILED;
  561. }
  562. if (!DBA::e("DELETE FROM `event` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
  563. return Update::FAILED;
  564. }
  565. if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
  566. return Update::FAILED;
  567. }
  568. if (!DBA::e("DELETE FROM `group_member` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
  569. return Update::FAILED;
  570. }
  571. if (!DBA::e("DELETE FROM `intro` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
  572. return Update::FAILED;
  573. }
  574. if (!DBA::e("DELETE FROM `participation` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
  575. return Update::FAILED;
  576. }
  577. if (!DBA::e("DELETE FROM `profile_check` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
  578. return Update::FAILED;
  579. }
  580. if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
  581. return Update::FAILED;
  582. }
  583. if (!DBA::e("DELETE FROM `participation` WHERE NOT `fid` IN (SELECT `id` FROM `fcontact`)")) {
  584. return Update::FAILED;
  585. }
  586. if (!DBA::e("DELETE FROM `group_member` WHERE NOT `gid` IN (SELECT `id` FROM `group`)")) {
  587. return Update::FAILED;
  588. }
  589. if (!DBA::e("DELETE FROM `gserver-tag` WHERE NOT `gserver-id` IN (SELECT `id` FROM `gserver`)")) {
  590. return Update::FAILED;
  591. }
  592. if (!DBA::e("DELETE FROM `participation` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
  593. return Update::FAILED;
  594. }
  595. if (!DBA::e("DELETE FROM `user-item` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
  596. return Update::FAILED;
  597. }
  598. return Update::SUCCESS;
  599. }
  600. function pre_update_1365()
  601. {
  602. if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `notify-id` IN (SELECT `id` FROM `notify`)")) {
  603. return Update::FAILED;
  604. }
  605. if (!DBA::e("DELETE FROM `thread` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
  606. return Update::FAILED;
  607. }
  608. }