]> git.mxchange.org Git - friendica.git/blobdiff - update.php
bug fix #1115
[friendica.git] / update.php
index c84329511f91025076c8cec32e4c9e5dcee49880..0ac59db951fe891edcc502291d629841d53d3e54 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define( 'UPDATE_VERSION' , 1170 );
+define( 'UPDATE_VERSION' , 1173 );
 
 /**
  *
@@ -10,29 +10,30 @@ define( 'UPDATE_VERSION' , 1170 );
  * copying the latest files from the source code repository will always perform a clean
  * and painless upgrade.
  *
- * Each function in this file is named update_nnnn() where nnnn is an increasing number 
+ * Each function in this file is named update_nnnn() where nnnn is an increasing number
  * which began counting at 1000.
- * 
+ *
  * At the top of the file "boot.php" is a define for DB_UPDATE_VERSION. Any time there is a change
  * to the database schema or one which requires an upgrade path from the existing application,
  * the DB_UPDATE_VERSION and the UPDATE_VERSION at the top of this file are incremented.
  *
  * The current DB_UPDATE_VERSION is stored in the config area of the database. If the application starts up
- * and DB_UPDATE_VERSION is greater than the last stored build number, we will process every update function 
- * in order from the currently stored value to the new DB_UPDATE_VERSION. This is expected to bring the system 
+ * and DB_UPDATE_VERSION is greater than the last stored build number, we will process every update function
+ * in order from the currently stored value to the new DB_UPDATE_VERSION. This is expected to bring the system
  * up to current without requiring re-installation or manual intervention.
  *
  * Once the upgrade functions have completed, the current DB_UPDATE_VERSION is stored as the current value.
- * The DB_UPDATE_VERSION will always be one greater than the last numbered script in this file. 
+ * The DB_UPDATE_VERSION will always be one greater than the last numbered script in this file.
  *
  * If you change the database schema, the following are required:
- *    1. Update the file database.sql to match the new schema.
- *    2. Update this file by adding a new function at the end with the number of the current DB_UPDATE_VERSION.
- *       This function should modify the current database schema and perform any other steps necessary
- *       to ensure that upgrade is silent and free from requiring interaction.
+ *    1. Update the file include/dbstructure.php to match the new schema.
+ *    2. If there is a need for a post procession, update this file by adding a new function at the end with the number of the current DB_UPDATE_VERSION.
+ *       This function should perform some post procession steps but no database updates.
  *    3. Increment the DB_UPDATE_VERSION in boot.php *AND* the UPDATE_VERSION in this file to match it
  *    4. TEST the upgrade prior to checkin and filing a pull request.
  *
+ * IMPORTANT!
+ * NEVER do a database change anymore in the update functions! Only do this in the file include/dbstructure.php!
  */
 
 
@@ -92,7 +93,7 @@ function update_1006() {
                        $spkey = openssl_pkey_get_details($sres);
                        $spubkey = $spkey["key"];
                        $r = q("UPDATE `user` SET `spubkey` = '%s', `sprvkey` = '%s'
-                               WHERE `uid` = %d LIMIT 1",
+                               WHERE `uid` = %d",
                                dbesc($spubkey),
                                dbesc($sprvkey),
                                intval($rr['uid'])
@@ -123,7 +124,7 @@ function update_1011() {
        $r = q("SELECT * FROM `contact` WHERE 1");
        if(count($r)) {
                foreach($r as $rr) {
-                               q("UPDATE `contact` SET `nick` = '%s' WHERE `id` = %d LIMIT 1",
+                               q("UPDATE `contact` SET `nick` = '%s' WHERE `id` = %d",
                                        dbesc(basename($rr['url'])),
                                        intval($rr['id'])
                                );
@@ -157,11 +158,11 @@ function update_1014() {
        if(count($r)) {
                foreach($r as $rr) {            
                        if(stristr($rr['thumb'],'avatar'))
-                               q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d LIMIT 1",
+                               q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d",
                                        dbesc(str_replace('avatar','micro',$rr['thumb'])),
                                        intval($rr['id']));
                        else
-                               q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d LIMIT 1",
+                               q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d",
                                        dbesc(str_replace('5.jpg','6.jpg',$rr['thumb'])),
                                        intval($rr['id']));
                }
@@ -310,7 +311,7 @@ function update_1031() {
        if($r && count($r)) {
                foreach($r as $rr) {
                        if(strstr($rr['object'],'type=&quot;http')) {
-                               q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d LIMIT 1",
+                               q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d",
                                        dbesc(str_replace('type=&quot;http','href=&quot;http',$rr['object'])),
                                        intval($rr['id'])
                                );
@@ -357,7 +358,7 @@ function update_1036() {
        $r = dbq("SELECT * FROM `contact` WHERE `network` = 'dfrn' && `photo` LIKE '%include/photo%' ");
        if(count($r)) {
                foreach($r as $rr) {
-                       q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d LIMIT 1",
+                       q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d",
                                dbesc(str_replace('include/photo','photo',$rr['photo'])),
                                dbesc(str_replace('include/photo','photo',$rr['thumb'])),
                                dbesc(str_replace('include/photo','photo',$rr['micro'])),
@@ -595,7 +596,7 @@ function update_1074() {
        $r = q("SELECT `uid` FROM `profile` WHERE `is-default` = 1 AND `hidewall` = 1");
        if(count($r)) {
                foreach($r as $rr)
-                       q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d LIMIT 1",
+                       q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d",
                                intval($rr['uid'])
                        );
        }
@@ -617,7 +618,7 @@ function update_1075() {
                                        $found = false;
                        } while ($found == true );
 
-                       q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d LIMIT 1",
+                       q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d",
                                dbesc($guid),
                                intval($rr['uid'])
                        );
@@ -736,7 +737,7 @@ function update_1087() {
                                intval($rr['id'])
                        );
                        if(count($x))
-                               q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d LIMIT 1",
+                               q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d",
                                        dbesc($x[0]['cdate']),
                                        intval($rr['id'])
                                );
@@ -855,7 +856,7 @@ function update_1100() {
        $r = q("select id, url from contact where url != '' and nurl = '' ");
        if(count($r)) {
                foreach($r as $rr) {
-                       q("update contact set nurl = '%s' where id = %d limit 1",
+                       q("update contact set nurl = '%s' where id = %d",
                                dbesc(normalise_link($rr['url'])),
                                intval($rr['id'])
                        ); 
@@ -1173,7 +1174,7 @@ function update_1136() {
                        foreach($arr as $x) {
                                if($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) {
                                        $found = true;
-                                       q("delete from config where id = %d limit 1",
+                                       q("delete from config where id = %d",
                                                intval($rr['id'])
                                        );
                                }
@@ -1192,7 +1193,7 @@ function update_1136() {
                        foreach($arr as $x) {
                                if($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) {
                                        $found = true;
-                                       q("delete from pconfig where id = %d limit 1",
+                                       q("delete from pconfig where id = %d",
                                                intval($rr['id'])
                                        );
                                }
@@ -1562,7 +1563,7 @@ function update_1169() {
        $r = q("CREATE TABLE IF NOT EXISTS `thread` (
                  `iid` int(10) unsigned NOT NULL DEFAULT '0',
                  `uid` int(10) unsigned NOT NULL DEFAULT '0',
-                 `contact-id` int(10) unsigned NOT NULL DEFAULT '0',
+                 `contact-id` int(11) unsigned NOT NULL DEFAULT '0',
                  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
                  `edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
                  `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -1583,17 +1584,15 @@ function update_1169() {
                  `mention` tinyint(1) NOT NULL DEFAULT '0',
                  `network` char(32) NOT NULL,
                  PRIMARY KEY (`iid`),
-                 KEY `uid` (`uid`),
-                 KEY `contact-id` (`contact-id`),
                  KEY `created` (`created`),
-                 KEY `edited` (`edited`),
                  KEY `commented` (`commented`),
-                 KEY `received` (`received`),
-                 KEY `changed` (`changed`),
-                 KEY `network` (`network`)
-                 KEY `visible_deleted_moderated_private_wall_received` (`visible`,`deleted`,`moderated`,`private`,`wall`,`received`),
-                 KEY `uid_visible_deleted_moderated_created` (`uid`,`visible`,`deleted`,`moderated`,`created`),
-                 KEY `uid_visible_deleted_moderated_commented` (`uid`,`visible`,`deleted`,`moderated`,`commented`)
+                 KEY `uid_network_commented` (`uid`,`network`,`commented`),
+                 KEY `uid_network_created` (`uid`,`network`,`created`),
+                 KEY `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
+                 KEY `uid_contactid_created` (`uid`,`contact-id`,`created`),
+                 KEY `wall_private_received` (`wall`,`private`,`received`),
+                 KEY `uid_created` (`uid`,`created`),
+                 KEY `uid_commented` (`uid`,`commented`)
                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;");
        if (!$r)
                return UPDATE_FAILED;
@@ -1602,3 +1601,13 @@ function update_1169() {
 
        return UPDATE_SUCCESS;
 }
+
+/*
+==========
+ATTENTION!
+==========
+
+All following update functions are ONLY for jobs that need to run AFTER the database changes are applied.
+
+Database changes are ONLY applied in the file include/dbstructure.php.
+*/