Last active
May 22, 2017 08:40
-
-
Save nickvergessen/c83981bafbbe55e3cf5bde09b901cfcf to your computer and use it in GitHub Desktop.
Repair problems with shipped apps on update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @copyright Copyright (c) 2016 Joas Schilling <[email protected]> | |
* | |
* @license GNU AGPL version 3 or any later version | |
* | |
* This program 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. | |
* | |
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | |
* | |
*/ | |
die('Do not execute this, unless you have been directly adviced to do so!'); | |
require_once __DIR__ . '/lib/base.php'; | |
foreach (\OC::$APPSROOTS as $app_dir) { | |
if ($dir = opendir($app_dir['path'])) { | |
while (false !== ($filename = readdir($dir))) { | |
if (substr($filename, 0, 1) != '.' && is_dir($app_dir['path'] . "/$filename")) { | |
if (file_exists($app_dir['path'] . "/$filename/appinfo/info.xml")) { | |
if (\OC::$server->getConfig()->getAppValue($filename, "installed_version", null) === null) { | |
$info = \OC_App::getAppInfo($filename); | |
$enabled = isset($info['default_enable']); | |
if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) | |
&& \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { | |
echo 'Fixing missing records for app: ' . $filename; | |
installOrUpdateShippedApp($filename); | |
\OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); | |
echo 'Fixed missing records for app: ' . $filename; | |
} | |
} | |
} | |
} | |
} | |
closedir( $dir ); | |
} | |
} | |
function installOrUpdateShippedApp($app) { | |
//install the database | |
$appPath = \OC_App::getAppPath($app); | |
if (is_file("$appPath/appinfo/database.xml")) { | |
try { | |
\OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); | |
} catch (\Doctrine\DBAL\Exception\TableExistsException $e) { | |
\OC_DB::updateDbFromStructure("$appPath/appinfo/database.xml"); | |
} | |
} | |
//run appinfo/install.php | |
\OC_App::registerAutoloading($app, $appPath); | |
include "$appPath/appinfo/install.php"; | |
$info = OC_App::getAppInfo($app); | |
if (is_null($info)) { | |
return false; | |
} | |
\OC_App::setupBackgroundJobs($info['background-jobs']); | |
\OC_App::executeRepairSteps($app, $info['repair-steps']['install']); | |
$config = \OC::$server->getConfig(); | |
$config->setAppValue($app, 'installed_version', \OC_App::getAppVersion($app)); | |
if (array_key_exists('ocsid', $info)) { | |
$config->setAppValue($app, 'ocsid', $info['ocsid']); | |
} | |
//set remote/public handlers | |
foreach ($info['remote'] as $name => $path) { | |
$config->setAppValue('core', 'remote_' . $name, $app . '/' . $path); | |
} | |
foreach ($info['public'] as $name => $path) { | |
$config->setAppValue('core', 'public_' . $name, $app . '/' . $path); | |
} | |
\OC_App::setAppTypes($info['id']); | |
if (isset($info['settings']) && is_array($info['settings'])) { | |
// requires that autoloading was registered for the app, | |
// as happens before running the install.php some lines above | |
\OC::$server->getSettingsManager()->setupSettings($info['settings']); | |
} | |
return $info['id']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment