unified most db upgrades:

- common way is to check on result ($r mostly) of db upgrade
- on success, return UPDATE_SUCCESS
- on failure, return UPDATE_FAILED

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2017-01-23 10:14:48 +01:00 committed by Roland Haeder
parent 63e4750b4a
commit 0b6336edb0
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78

View file

@ -37,7 +37,7 @@ define('UPDATE_VERSION' , 1215);
*/
/// @TODO These old updates need to have UPDATE_SUCCESS returned on success?
function update_1000() {
q("ALTER TABLE `item` DROP `like`, DROP `dislike` ");
@ -308,7 +308,7 @@ function update_1030() {
function update_1031() {
// Repair any bad links that slipped into the item table
$r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' ");
if($r && dbm::is_result($r)) {
if (dbm::is_result($r)) {
foreach ($r as $rr) {
if(strstr($rr['object'],'type=&quot;http')) {
q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d",
@ -368,9 +368,7 @@ function update_1036() {
}
function update_1037() {
q("ALTER TABLE `contact` CHANGE `lrdd` `alias` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
}
function update_1038() {
@ -532,8 +530,10 @@ function update_1065() {
function update_1066() {
$r = q("ALTER TABLE `item` ADD `received` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` ");
if($r)
if ($r) {
q("ALTER TABLE `item` ADD INDEX ( `received` ) ");
}
$r = q("UPDATE `item` SET `received` = `edited` WHERE 1");
}
@ -567,6 +567,7 @@ function update_1069() {
q("ALTER TABLE `fcontact` ADD `request` CHAR( 255 ) NOT NULL AFTER `photo` ");
}
/// @TODO Still meeded?
// mail body needs to accomodate private photos
function update_1070() {
@ -614,8 +615,9 @@ function update_1075() {
$x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
dbesc($guid)
);
if(! count($x))
if (!dbm::is_result($x)) {
$found = false;
}
} while ($found == true );
q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d",
@ -684,14 +686,19 @@ function update_1082() {
q("ALTER TABLE `photo` ADD `guid` CHAR( 64 ) NOT NULL AFTER `contact-id`,
ADD INDEX ( `guid` ) ");
// make certain the following code is only executed once
$r = q("select `id` from `photo` where `guid` != '' limit 1");
if (dbm::is_result($r))
$r = q("SELECT `id` FROM `photo` WHERE `guid` != '' LIMIT 1");
if (dbm::is_result($r)) {
return;
}
$r = q("SELECT distinct(`resource-id`) FROM `photo` WHERE 1 group by `id`");
if (dbm::is_result($r)) {
foreach ($r as $rr) {
$guid = get_guid();
q("update `photo` set `guid` = '%s' where `resource-id` = '%s'",
q("UPDATE `photo` SET `guid` = '%s' WHERE `resource-id` = '%s'",
dbesc($guid),
dbesc($rr['resource-id'])
);
@ -736,7 +743,8 @@ function update_1087() {
$x = q("SELECT max(`created`) AS `cdate` FROM `item` WHERE `parent` = %d LIMIT 1",
intval($rr['id'])
);
if(count($x))
if (dbm::is_result($x)) {
q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d",
dbesc($x[0]['cdate']),
intval($rr['id'])
@ -744,6 +752,7 @@ function update_1087() {
}
}
}
}
function update_1088() {
q("ALTER TABLE `user` ADD `account_expired` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `expire` ,
@ -849,14 +858,14 @@ function update_1099() {
function update_1100() {
q("ALTER TABLE `contact` ADD `nurl` CHAR( 255 ) NOT NULL AFTER `url` ");
q("alter table contact add index (`nurl`) ");
q("ALTER TABLE `contact` ADD INDEX (`nurl`) ");
require_once('include/text.php');
$r = q("select id, url from contact where url != '' and nurl = '' ");
$r = q("SELECT `id`, `url` FROM `contact` WHERE `url` != '' AND `nurl` = '' ");
if (dbm::is_result($r)) {
foreach ($r as $rr) {
q("update contact set nurl = '%s' where id = %d",
q("UPDATE `contact` SET `nurl` = '%s' WHERE `id` = %d",
dbesc(normalise_link($rr['url'])),
intval($rr['id'])
);
@ -886,6 +895,7 @@ function update_1102() {
function update_1103() {
/// @TODO Comented out:
// q("ALTER TABLE `item` ADD INDEX ( `wall` ) ");
q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) ");
q("ALTER TABLE `contact` ADD INDEX ( `pending` ) ");
@ -1031,10 +1041,12 @@ function update_1120() {
$r = q("describe item");
if (dbm::is_result($r)) {
foreach($r as $rr)
if($rr['Field'] == 'spam')
foreach($r as $rr) {
if ($rr['Field'] == 'spam') {
return;
}
}
}
q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) ");
}
@ -1076,7 +1088,7 @@ set_config('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,d
}
function update_1124() {
q("alter table item add index (`author-name`) ");
q("ALTER TABLE `item` ADD INDEX (`author-name`) ");
}
function update_1125() {
@ -1112,7 +1124,7 @@ function update_1127() {
function update_1128() {
q("alter table spam add `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `term` ");
q("ALTER TABLE `spam` ADD `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `term` ");
}
function update_1129() {
@ -1167,14 +1179,14 @@ function update_1136() {
// order in reverse so that we save the newest entry
$r = q("select * from config where 1 order by id desc");
$r = q("SELECT * FROM `config` WHERE 1 ORDER BY `id` DESC");
if (dbm::is_result($r)) {
foreach ($r as $rr) {
$found = false;
foreach ($arr as $x) {
if ($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) {
$found = true;
q("delete from config where id = %d",
q("DELETE FROM `config` WHERE `id` = %d",
intval($rr['id'])
);
}
@ -1186,14 +1198,14 @@ function update_1136() {
}
$arr = array();
$r = q("select * from pconfig where 1 order by id desc");
$r = q("SELECT * FROM `pconfig` WHERE 1 ORDER BY `id` DESC");
if (dbm::is_result($r)) {
foreach ($r as $rr) {
$found = false;
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",
q("DELETE FROM `pconfig` WHERE `id` = %d",
intval($rr['id'])
);
}
@ -1210,104 +1222,140 @@ function update_1136() {
function update_1137() {
q("alter table item_id DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` ");
q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , add index (`sid`), add index ( `service`) ");
q("ALTER TABLE `item_id` DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` ");
q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , ADD INDEX (`sid`), ADD INDEX ( `service`) ");
}
function update_1138() {
q("alter table contact add archive tinyint(1) not null default '0' after hidden, add index (archive)");
q("ALTER TABLE `contact` ADD `archive` TINYINT(1) NOT NULL DEFAULT '0' AFTER `hidden`, ADD INDEX (`archive`)");
}
function update_1139() {
$r = q("alter table user add account_removed tinyint(1) not null default '0' after expire, add index(account_removed) ");
if(! $r)
return UPDATE_FAILED ;
$r = q("ALTER TABLE `user` ADD `account_removed` TINYINT(1) NOT NULL DEFAULT '0' AFTER `expire`, ADD INDEX(`account_removed`)");
if ($r) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1140() {
$r = q("alter table addon add hidden tinyint(1) not null default '0' after installed, add index(hidden) ");
if(! $r)
return UPDATE_FAILED ;
$r = q("ALTER TABLE `addon` ADD `hidden` TINYINT(1) NOT NULL DEFAULT '0' AFTER `installed`, ADD INDEX(`hidden`) ");
if ($r) {
return UPDATE_SUCCESS ;
}
function update_1141() {
$r = q("alter table glink add zcid int(11) not null after gcid, add index(zcid) ");
if(! $r)
return UPDATE_FAILED ;
}
function update_1141() {
$r = q("ALTER TABLE `glink` ADD `zcid` INT(11) NOT NULL AFTER `gcid`, ADD INDEX(`zcid`) ");
if ($r) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1142() {
$r = q("alter table user add service_class char(32) not null after expire_notification_sent, add index(service_class) ");
if(! $r)
return UPDATE_FAILED ;
$r = q("ALTER TABLE `user` ADD `service_class` CHAR(32) NOT NULL AFTER `expire_notification_sent`, ADD INDEX(`service_class`) ");
if ($r) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1143() {
$r = q("alter table user add def_gid int(11) not null default '0' after service_class");
if(! $r)
return UPDATE_FAILED ;
$r = q("ALTER TABLE `user` ADD `def_gid` INT(11) NOT NULL DEFAULT '0' AFTER `service_class`");
if ($r) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1144() {
$r = q("alter table contact add prv tinyint(1) not null default '0' after forum");
if(! $r)
return UPDATE_FAILED ;
$r = q("ALTER TABLE `contact` ADD `prv` TINYINT(1) NOT NULL DEFAULT '0' AFTER `forum`");
if ($r) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1145() {
$r = q("alter table profile add howlong datetime not null default '0000-00-00 00:00:00' after `with`");
if(! $r)
return UPDATE_FAILED ;
$r = q("ALTER TABLE `profile` ADD `howlong` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `with`");
if ($r) {
return UPDATE_SUCCESS ;
}
function update_1146() {
$r = q("alter table profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) ");
if(! $r)
return UPDATE_FAILED ;
}
function update_1146() {
$r = q("ALTER TABLE profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) ");
if ($r) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1147() {
$r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'");
$r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`");
$r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )");
if((! $r1) || (! $r2) || (! $r3))
return UPDATE_FAILED ;
if ($r1 && $r2 && $r3) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1148() {
$r = q("ALTER TABLE photo ADD type CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER filename");
if (!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1149() {
$r1 = q("ALTER TABLE profile ADD likes text NOT NULL after prv_keywords");
$r2 = q("ALTER TABLE profile ADD dislikes text NOT NULL after likes");
if (! ($r1 && $r2))
return UPDATE_FAILED;
if ($r1 && $r2) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1150() {
$r = q("ALTER TABLE event ADD summary text NOT NULL after finish, add index ( uid ), add index ( cid ), add index ( uri ), add index ( `start` ), add index ( finish ), add index ( `type` ), add index ( adjust ) ");
if(! $r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1151() {
$r = q("CREATE TABLE IF NOT EXISTS locks (
@ -1315,11 +1363,14 @@ function update_1151() {
name CHAR( 128 ) NOT NULL ,
locked TINYINT( 1 ) NOT NULL DEFAULT '0'
) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
if (!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1152() {
$r = q("CREATE TABLE IF NOT EXISTS `term` (
`tid` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
@ -1333,32 +1384,42 @@ function update_1152() {
KEY `type` ( `type` ),
KEY `term` ( `term` )
) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
if (!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1153() {
$r = q("ALTER TABLE `hook` ADD `priority` INT(11) UNSIGNED NOT NULL DEFAULT '0'");
if(!$r) return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1154() {
$r = q("ALTER TABLE `event` ADD `ignore` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `adjust` , ADD INDEX ( `ignore` )");
if(!$r) return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1155() {
$r1 = q("ALTER TABLE `item_id` DROP PRIMARY KEY");
$r2 = q("ALTER TABLE `item_id` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
$r3 = q("ALTER TABLE `item_id` ADD INDEX ( `iid` ) ");
if($r1 && $r2 && $r3)
if ($r1 && $r2 && $r3) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
@ -1367,10 +1428,13 @@ function update_1156() {
$r = q("ALTER TABLE `photo` ADD `datasize` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `width` ,
ADD INDEX ( `datasize` ) ");
if(!$r) return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1157() {
$r = q("CREATE TABLE IF NOT EXISTS `dsprphotoq` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
@ -1381,10 +1445,13 @@ function update_1157() {
) ENGINE=MyISAM DEFAULT CHARSET=utf8"
);
if($r)
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1158() {
set_config('system', 'maintenance', 1);
@ -1395,8 +1462,9 @@ function update_1158() {
$r = q("CREATE INDEX event_id ON item(`event-id`)");
set_config('system', 'maintenance', 0);
if($r)
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
@ -1407,12 +1475,13 @@ function update_1159() {
ADD INDEX (`uid`),
ADD INDEX (`aid`)");
if(!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1160() {
set_config('system', 'maintenance', 1);
@ -1423,21 +1492,23 @@ function update_1160() {
$r = q("ALTER TABLE `item` ADD `mention` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX (`mention`)");
set_config('system', 'maintenance', 0);
if(!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1161() {
$r = q("ALTER TABLE `pconfig` ADD INDEX (`cat`)");
if(!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1162() {
require_once('include/tags.php');
update_items();
@ -1451,14 +1522,17 @@ function update_1163() {
$r = q("ALTER TABLE `item` ADD `network` char(32) NOT NULL");
set_config('system', 'maintenance', 0);
if(!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1164() {
set_config('system', 'maintenance', 1);
/// @TODO If one update fails, should it continue?
$r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '' AND `contact`.`uid` = `item`.`uid`)",
NETWORK_DFRN);
@ -1520,12 +1594,14 @@ function update_1165() {
`last_update` DATETIME NOT NULL,
`secret` CHAR( 255 ) NOT NULL
) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
if (!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1166() {
$r = q("CREATE TABLE IF NOT EXISTS `unique_contacts` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
@ -1535,28 +1611,34 @@ function update_1166() {
`avatar` CHAR(255) NOT NULL,
INDEX (`url`)
) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
if (!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1167() {
$r = q("ALTER TABLE `contact` ADD `notify_new_posts` TINYINT(1) NOT NULL DEFAULT '0'");
if (!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS;
}
return UPDATE_FAILED;
}
function update_1168() {
$r = q("ALTER TABLE `contact` ADD `fetch_further_information` TINYINT(1) NOT NULL DEFAULT '0'");
if (!$r)
return UPDATE_FAILED;
if ($r) {
return UPDATE_SUCCESS ;
}
return UPDATE_FAILED ;
}
function update_1169() {
$r = q("CREATE TABLE IF NOT EXISTS `thread` (
`iid` int(10) unsigned NOT NULL DEFAULT '0',
@ -1592,8 +1674,10 @@ function update_1169() {
KEY `uid_created` (`uid`,`created`),
KEY `uid_commented` (`uid`,`commented`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
if (!$r)
if (!$r) {
return UPDATE_FAILED;
}
proc_run(PRIORITY_LOW, "include/threadupdate.php");