Minor reformatting of upgrade.php, doesn't change functionality
This commit is contained in:
parent
5eb61c17d4
commit
30a1a460b7
@ -1,27 +1,36 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
/*
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
* StatusNet - a distributed open-source microblogging tool
|
//
|
||||||
* Copyright (C) 2008-2011 StatusNet, Inc.
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GNU social is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade database schema and data to latest software and check DB integrity
|
||||||
|
* Usage: php upgrade.php [options]
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* @package GNUsocial
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
* @author Bhuvan Krishna <bhuvan@swecha.net>
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* @author Evan Prodromou <evan@status.net>
|
||||||
* (at your option) any later version.
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
||||||
*
|
* @copyright 2010-2019 Free Software Foundation, Inc http://www.fsf.org
|
||||||
* This program is distributed in the hope that it will be useful,
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
|
define('INSTALLDIR', dirname(__DIR__));
|
||||||
|
|
||||||
$shortoptions = 'dfx::';
|
$shortoptions = 'dfx::';
|
||||||
$longoptions = array('debug', 'files', 'extensions=');
|
$longoptions = ['debug', 'files', 'extensions='];
|
||||||
|
|
||||||
$helptext = <<<END_OF_UPGRADE_HELP
|
$helptext = <<<END_OF_UPGRADE_HELP
|
||||||
php upgrade.php [options]
|
php upgrade.php [options]
|
||||||
@ -82,8 +91,8 @@ function main()
|
|||||||
|
|
||||||
function tableDefs()
|
function tableDefs()
|
||||||
{
|
{
|
||||||
$schema = array();
|
$schema = [];
|
||||||
require INSTALLDIR.'/db/core.php';
|
require INSTALLDIR . '/db/core.php';
|
||||||
return $schema;
|
return $schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,24 +210,27 @@ function initConversation()
|
|||||||
}
|
}
|
||||||
|
|
||||||
while ($notice->fetch()) {
|
while ($notice->fetch()) {
|
||||||
|
|
||||||
$id = $notice->conversation;
|
$id = $notice->conversation;
|
||||||
|
|
||||||
$uri = common_local_url('conversation', array('id' => $id));
|
$uri = common_local_url('conversation', ['id' => $id]);
|
||||||
|
|
||||||
// @fixme db_dataobject won't save our value for an autoincrement
|
// @fixme db_dataobject won't save our value for an autoincrement
|
||||||
// so we're bypassing the insert wrappers
|
// so we're bypassing the insert wrappers
|
||||||
$conv = new Conversation();
|
$conv = new Conversation();
|
||||||
$sql = "insert into conversation (id,uri,created) values(%d,'%s','%s')";
|
$sql = "INSERT INTO conversation (id,uri,created) VALUES (%d,'%s','%s')";
|
||||||
$sql = sprintf($sql,
|
$sql = sprintf(
|
||||||
|
$sql,
|
||||||
$id,
|
$id,
|
||||||
$conv->escape($uri),
|
$conv->escape($uri),
|
||||||
$conv->escape(common_sql_now()));
|
$conv->escape(common_sql_now())
|
||||||
|
);
|
||||||
$conv->query($sql);
|
$conv->query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is something we should only have to do once unless introducing new, bad code.
|
// This is something we should only have to do once unless introducing new, bad code.
|
||||||
if (DEBUG) printfnq(sprintf('Storing in config that we have done %s', __METHOD__));
|
if (DEBUG) {
|
||||||
|
printfnq(sprintf('Storing in config that we have done %s', __METHOD__));
|
||||||
|
}
|
||||||
common_config_set('fix', 'upgrade_initConversation', 1);
|
common_config_set('fix', 'upgrade_initConversation', 1);
|
||||||
|
|
||||||
printfnq("DONE.\n");
|
printfnq("DONE.\n");
|
||||||
@ -234,9 +246,12 @@ function fixupConversationURIs()
|
|||||||
if ($conv->find()) {
|
if ($conv->find()) {
|
||||||
$rounds = 0;
|
$rounds = 0;
|
||||||
while ($conv->fetch()) {
|
while ($conv->fetch()) {
|
||||||
$uri = common_local_url('conversation', array('id' => $conv->id));
|
$uri = common_local_url('conversation', ['id' => $conv->id]);
|
||||||
$sql = sprintf('UPDATE conversation SET uri="%1$s" WHERE id="%2$d";',
|
$sql = sprintf(
|
||||||
$conv->escape($uri), $conv->id);
|
'UPDATE conversation SET uri="%1$s" WHERE id="%2$d";',
|
||||||
|
$conv->escape($uri),
|
||||||
|
$conv->id
|
||||||
|
);
|
||||||
$conv->query($sql);
|
$conv->query($sql);
|
||||||
if (($conv->N-++$rounds) % 500 == 0) {
|
if (($conv->N-++$rounds) % 500 == 0) {
|
||||||
printfnq(sprintf(' %d items left...', $conv->N-$rounds));
|
printfnq(sprintf(' %d items left...', $conv->N-$rounds));
|
||||||
@ -297,7 +312,7 @@ function initLocalGroup()
|
|||||||
while ($group->fetch()) {
|
while ($group->fetch()) {
|
||||||
try {
|
try {
|
||||||
// Hack to check for local groups
|
// Hack to check for local groups
|
||||||
if ($group->getUri() == common_local_url('groupbyid', array('id' => $group->id))) {
|
if ($group->getUri() == common_local_url('groupbyid', ['id' => $group->id])) {
|
||||||
$lg = new Local_group();
|
$lg = new Local_group();
|
||||||
|
|
||||||
$lg->group_id = $group->id;
|
$lg->group_id = $group->id;
|
||||||
@ -342,7 +357,9 @@ function initNoticeReshare()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This is something we should only have to do once unless introducing new, bad code.
|
// This is something we should only have to do once unless introducing new, bad code.
|
||||||
if (DEBUG) printfnq(sprintf('Storing in config that we have done %s', __METHOD__));
|
if (DEBUG) {
|
||||||
|
printfnq(sprintf('Storing in config that we have done %s', __METHOD__));
|
||||||
|
}
|
||||||
common_config_set('fix', 'upgrade_initNoticeReshare', 1);
|
common_config_set('fix', 'upgrade_initNoticeReshare', 1);
|
||||||
|
|
||||||
printfnq("DONE.\n");
|
printfnq("DONE.\n");
|
||||||
@ -359,13 +376,15 @@ function initSubscriptionURI()
|
|||||||
while ($sub->fetch()) {
|
while ($sub->fetch()) {
|
||||||
try {
|
try {
|
||||||
$sub->decache();
|
$sub->decache();
|
||||||
$sub->query(sprintf('update subscription '.
|
$sub->query(sprintf(
|
||||||
'set uri = "%s" '.
|
'UPDATE subscription '.
|
||||||
'where subscriber = %d '.
|
'SET uri = "%s" '.
|
||||||
'and subscribed = %d',
|
'WHERE subscriber = %d '.
|
||||||
|
'AND subscribed = %d',
|
||||||
$sub->escape(Subscription::newUri($sub->getSubscriber(), $sub->getSubscribed(), $sub->created)),
|
$sub->escape(Subscription::newUri($sub->getSubscriber(), $sub->getSubscribed(), $sub->created)),
|
||||||
$sub->subscriber,
|
$sub->subscriber,
|
||||||
$sub->subscribed));
|
$sub->subscribed
|
||||||
|
));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_log(LOG_ERR, "Error updated subscription URI: " . $e->getMessage());
|
common_log(LOG_ERR, "Error updated subscription URI: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
@ -386,12 +405,15 @@ function initGroupMemberURI()
|
|||||||
while ($mem->fetch()) {
|
while ($mem->fetch()) {
|
||||||
try {
|
try {
|
||||||
$mem->decache();
|
$mem->decache();
|
||||||
$mem->query(sprintf('update group_member set uri = "%s" '.
|
$mem->query(sprintf(
|
||||||
'where profile_id = %d ' .
|
'UPDATE group_member '.
|
||||||
'and group_id = %d ',
|
'SET uri = "%s" '.
|
||||||
|
'WHERE profile_id = %d ' .
|
||||||
|
'AND group_id = %d',
|
||||||
Group_member::newUri(Profile::getByID($mem->profile_id), User_group::getByID($mem->group_id), $mem->created),
|
Group_member::newUri(Profile::getByID($mem->profile_id), User_group::getByID($mem->group_id), $mem->created),
|
||||||
$mem->profile_id,
|
$mem->profile_id,
|
||||||
$mem->group_id));
|
$mem->group_id
|
||||||
|
));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_log(LOG_ERR, "Error updated membership URI: " . $e->getMessage());
|
common_log(LOG_ERR, "Error updated membership URI: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
@ -407,10 +429,10 @@ function initProfileLists()
|
|||||||
|
|
||||||
$ptag = new Profile_tag();
|
$ptag = new Profile_tag();
|
||||||
$ptag->selectAdd();
|
$ptag->selectAdd();
|
||||||
$ptag->selectAdd('tagger, tag, count(*) as tagged_count');
|
$ptag->selectAdd('tagger, tag, COUNT(*) AS tagged_count');
|
||||||
$ptag->whereAdd('NOT EXISTS (SELECT tagger, tagged from profile_list '.
|
$ptag->whereAdd('NOT EXISTS (SELECT tagger, tagged FROM profile_list '.
|
||||||
'where profile_tag.tagger = profile_list.tagger '.
|
'WHERE profile_tag.tagger = profile_list.tagger '.
|
||||||
'and profile_tag.tag = profile_list.tag)');
|
'AND profile_tag.tag = profile_list.tag)');
|
||||||
$ptag->groupBy('tagger, tag');
|
$ptag->groupBy('tagger, tag');
|
||||||
$ptag->orderBy('tagger, tag');
|
$ptag->orderBy('tagger, tag');
|
||||||
|
|
||||||
@ -423,9 +445,12 @@ function initProfileLists()
|
|||||||
$plist->private = 0;
|
$plist->private = 0;
|
||||||
$plist->created = common_sql_now();
|
$plist->created = common_sql_now();
|
||||||
$plist->modified = $plist->created;
|
$plist->modified = $plist->created;
|
||||||
$plist->mainpage = common_local_url('showprofiletag',
|
$plist->mainpage = common_local_url(
|
||||||
array('tagger' => $plist->getTagger()->nickname,
|
'showprofiletag',
|
||||||
'tag' => $plist->tag));;
|
['tagger' => $plist->getTagger()->nickname,
|
||||||
|
'tag' => $plist->tag]
|
||||||
|
);
|
||||||
|
;
|
||||||
|
|
||||||
$plist->tagged_count = $ptag->tagged_count;
|
$plist->tagged_count = $ptag->tagged_count;
|
||||||
$plist->subscriber_count = 0;
|
$plist->subscriber_count = 0;
|
||||||
@ -434,8 +459,11 @@ function initProfileLists()
|
|||||||
|
|
||||||
$orig = clone($plist);
|
$orig = clone($plist);
|
||||||
// After insert since it uses auto-generated ID
|
// After insert since it uses auto-generated ID
|
||||||
$plist->uri = common_local_url('profiletagbyid',
|
$plist->uri = common_local_url(
|
||||||
array('id' => $plist->id, 'tagger_id' => $plist->tagger));
|
'profiletagbyid',
|
||||||
|
['id' => $plist->id,
|
||||||
|
'tagger_id' => $plist->tagger]
|
||||||
|
);
|
||||||
|
|
||||||
$plist->update($orig);
|
$plist->update($orig);
|
||||||
}
|
}
|
||||||
@ -457,25 +485,33 @@ function fixupFileGeometry()
|
|||||||
|
|
||||||
if ($file->find()) {
|
if ($file->find()) {
|
||||||
while ($file->fetch()) {
|
while ($file->fetch()) {
|
||||||
if (DEBUG) printfnq(sprintf('Found file without width: %s\n', _ve($file->getFilename())));
|
if (DEBUG) {
|
||||||
|
printfnq(sprintf('Found file without width: %s\n', _ve($file->getFilename())));
|
||||||
|
}
|
||||||
|
|
||||||
// Set file geometrical properties if available
|
// Set file geometrical properties if available
|
||||||
try {
|
try {
|
||||||
$image = ImageFile::fromFileObject($file);
|
$image = ImageFile::fromFileObject($file);
|
||||||
} catch (ServerException $e) {
|
} catch (ServerException $e) {
|
||||||
// We couldn't make out an image from the file.
|
// We couldn't make out an image from the file.
|
||||||
if (DEBUG) printfnq(sprintf('Could not make an image out of the file.\n'));
|
if (DEBUG) {
|
||||||
|
printfnq(sprintf('Could not make an image out of the file.\n'));
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$orig = clone($file);
|
$orig = clone($file);
|
||||||
$file->width = $image->width;
|
$file->width = $image->width;
|
||||||
$file->height = $image->height;
|
$file->height = $image->height;
|
||||||
if (DEBUG) printfnq(sprintf('Setting image file and with to %sx%s.\n', $file->width, $file->height));
|
if (DEBUG) {
|
||||||
|
printfnq(sprintf('Setting image file and with to %sx%s.\n', $file->width, $file->height));
|
||||||
|
}
|
||||||
$file->update($orig);
|
$file->update($orig);
|
||||||
|
|
||||||
// FIXME: Do this more automagically inside ImageFile or so.
|
// FIXME: Do this more automagically inside ImageFile or so.
|
||||||
if ($image->getPath() != $file->getPath()) {
|
if ($image->getPath() != $file->getPath()) {
|
||||||
if (DEBUG) printfnq(sprintf('Deleting the temporarily stored ImageFile.\n'));
|
if (DEBUG) {
|
||||||
|
printfnq(sprintf('Deleting the temporarily stored ImageFile.\n'));
|
||||||
|
}
|
||||||
$image->unlink();
|
$image->unlink();
|
||||||
}
|
}
|
||||||
unset($image);
|
unset($image);
|
||||||
@ -581,10 +617,10 @@ function migrateProfilePrefs()
|
|||||||
{
|
{
|
||||||
printfnq("Finding and possibly migrating Profile_prefs entries: ");
|
printfnq("Finding and possibly migrating Profile_prefs entries: ");
|
||||||
|
|
||||||
$prefs = array(); // ['qvitter' => ['cover_photo'=>'profile_banner_url', ...], ...]
|
$prefs = []; // ['qvitter' => ['cover_photo'=>'profile_banner_url', ...], ...]
|
||||||
Event::handle('GetProfilePrefsMigrations', array(&$prefs));
|
Event::handle('GetProfilePrefsMigrations', [&$prefs]);
|
||||||
|
|
||||||
foreach($prefs as $namespace=>$mods) {
|
foreach ($prefs as $namespace=>$mods) {
|
||||||
echo "$namespace... ";
|
echo "$namespace... ";
|
||||||
assert(is_array($mods));
|
assert(is_array($mods));
|
||||||
$p = new Profile_prefs();
|
$p = new Profile_prefs();
|
||||||
|
Loading…
Reference in New Issue
Block a user