summaryrefslogtreecommitdiffstats
path: root/app/classes
diff options
context:
space:
mode:
authorrdalverny <rdalverny@gmail.com>2022-01-22 18:54:11 +0100
committerrdalverny <rdalverny@gmail.com>2022-01-22 18:54:11 +0100
commitc27c9d1d359828a071159995689c9c3b28d99891 (patch)
tree8aa8e0e2ea11935c34cee67f2a8f44201329b7e8 /app/classes
parent58ce95a255c04e1b6ecac0d794bc4dbeb23871de (diff)
downloadplanet-c27c9d1d359828a071159995689c9c3b28d99891.tar
planet-c27c9d1d359828a071159995689c9c3b28d99891.tar.gz
planet-c27c9d1d359828a071159995689c9c3b28d99891.tar.bz2
planet-c27c9d1d359828a071159995689c9c3b28d99891.tar.xz
planet-c27c9d1d359828a071159995689c9c3b28d99891.zip
Move public resources under public/ directory
Existing setups need to update their server config to point (or link to) public/ directory instead of the root of the code repo. Configuration (and password) location also changes from custom/ and admin/inc to custom/config/. That way, config and code library move out of the publicly served file tree. Apart from the change of the web root, config should be migrated seamlessly.
Diffstat (limited to 'app/classes')
-rw-r--r--app/classes/PlanetConfig.php76
1 files changed, 64 insertions, 12 deletions
diff --git a/app/classes/PlanetConfig.php b/app/classes/PlanetConfig.php
index b8233e0..6094956 100644
--- a/app/classes/PlanetConfig.php
+++ b/app/classes/PlanetConfig.php
@@ -41,23 +41,31 @@ class PlanetConfig
public static function load(string $dir)
{
$config = new PlanetConfig;
- $configFile = realpath($dir . '/../custom/config.yml');
- if (self::isInstalled()) {
- $conf = Spyc::YAMLLoad($configFile);
-
- // this is a check to upgrade older config file without l10n
- if (!isset($conf['locale'])) {
- $resetPlanetConfig = new PlanetConfig($conf);
- file_put_contents($configFile, $resetPlanetConfig->toYaml());
- $conf = Spyc::YAMLLoad($configFile);
+ if (!self::isInstalled()) {
+ if (!self::isInstalledPre10Version()) {
+ return $config;
+ }
- return $resetPlanetConfig;
+ if (!self::migratePre10Version()) {
+ error_log('Failed to migrate configuration.');
+ return $config;
}
+ }
- $config = new PlanetConfig($conf);
+ $configFile = realpath(config_path('config.yml'));
+ $conf = Spyc::YAMLLoad($configFile);
+
+ // this is a check to upgrade older config file without l10n
+ if (!isset($conf['locale'])) {
+ $resetPlanetConfig = new PlanetConfig($conf);
+ file_put_contents($configFile, $resetPlanetConfig->toYaml());
+ $conf = Spyc::YAMLLoad($configFile);
+ return $resetPlanetConfig;
}
+ $config = new PlanetConfig($conf);
+
return $config;
}
@@ -68,11 +76,55 @@ class PlanetConfig
*/
public static function isInstalled() : bool
{
+ return file_exists(config_path('config.yml')) &&
+ file_exists(config_path('people.opml'));
+ }
+
+ /**
+ * Or is it a pre-10 version installed?
+ * (that is, config is stored in custom/config.yml instead of custom/config/config.yml)
+ */
+ public static function isInstalledPre10Version(): bool
+ {
return file_exists(custom_path('config.yml')) &&
file_exists(custom_path('people.opml'));
}
/**
+ * Migrate config files from old to new location.
+ * Purge cache.
+ *
+ * @return bool true if succeeded, false otherwise
+ */
+ public static function migratePre10Version() : bool
+ {
+ if (!is_dir(config_path())) {
+ if (!mkdir(config_path(), 0777, true)) {
+ return false;
+ }
+ }
+
+ return self::migrate_file('config.yml') &&
+ self::migrate_file('people.opml');
+ }
+
+ public static function migrate_file($file) : bool
+ {
+ $source = custom_path($file);
+ $dest = config_path($file);
+ if (!copy($source, $source . '.bak')) {
+ error_log("Failed to make a backup of ${source}");
+ return false;
+ }
+ if (!rename($source, $dest)) {
+ error_log("Failed to move ${source} to ${dest}");
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
* Merge the configuration of the user in the default one.
*
* @param array $default
@@ -115,7 +167,7 @@ class PlanetConfig
public function getOpmlFile()
{
if (is_null($this->opmlFile)) {
- $this->opmlFile = realpath(__DIR__ . '/../../custom/people.opml');
+ $this->opmlFile = realpath(config_path('people.opml'));
}
return $this->opmlFile;
}