diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-06-09 20:04:02 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-06-11 09:30:56 +0200 |
commit | 278d9ee2836df7d805845077f26f8cecd16f0f4f (patch) | |
tree | 9155cab8890074e83b54efaa649bfa74885d3ab5 /application/Updater.php | |
parent | 7f179985b497053c59338667fe49c390aa626ab7 (diff) | |
download | Shaarli-278d9ee2836df7d805845077f26f8cecd16f0f4f.tar.gz Shaarli-278d9ee2836df7d805845077f26f8cecd16f0f4f.tar.zst Shaarli-278d9ee2836df7d805845077f26f8cecd16f0f4f.zip |
ConfigManager no longer uses singleton pattern
Diffstat (limited to 'application/Updater.php')
-rw-r--r-- | application/Updater.php | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/application/Updater.php b/application/Updater.php index db2144fe..b8940e41 100644 --- a/application/Updater.php +++ b/application/Updater.php | |||
@@ -18,6 +18,11 @@ class Updater | |||
18 | protected $linkDB; | 18 | protected $linkDB; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * @var ConfigManager $conf Configuration Manager instance. | ||
22 | */ | ||
23 | protected $conf; | ||
24 | |||
25 | /** | ||
21 | * @var bool True if the user is logged in, false otherwise. | 26 | * @var bool True if the user is logged in, false otherwise. |
22 | */ | 27 | */ |
23 | protected $isLoggedIn; | 28 | protected $isLoggedIn; |
@@ -30,14 +35,16 @@ class Updater | |||
30 | /** | 35 | /** |
31 | * Object constructor. | 36 | * Object constructor. |
32 | * | 37 | * |
33 | * @param array $doneUpdates Updates which are already done. | 38 | * @param array $doneUpdates Updates which are already done. |
34 | * @param LinkDB $linkDB LinkDB instance. | 39 | * @param LinkDB $linkDB LinkDB instance. |
35 | * @param boolean $isLoggedIn True if the user is logged in. | 40 | * @oaram ConfigManager $conf Configuration Manager instance. |
41 | * @param boolean $isLoggedIn True if the user is logged in. | ||
36 | */ | 42 | */ |
37 | public function __construct($doneUpdates, $linkDB, $isLoggedIn) | 43 | public function __construct($doneUpdates, $linkDB, $conf, $isLoggedIn) |
38 | { | 44 | { |
39 | $this->doneUpdates = $doneUpdates; | 45 | $this->doneUpdates = $doneUpdates; |
40 | $this->linkDB = $linkDB; | 46 | $this->linkDB = $linkDB; |
47 | $this->conf = $conf; | ||
41 | $this->isLoggedIn = $isLoggedIn; | 48 | $this->isLoggedIn = $isLoggedIn; |
42 | 49 | ||
43 | // Retrieve all update methods. | 50 | // Retrieve all update methods. |
@@ -107,21 +114,19 @@ class Updater | |||
107 | */ | 114 | */ |
108 | public function updateMethodMergeDeprecatedConfigFile() | 115 | public function updateMethodMergeDeprecatedConfigFile() |
109 | { | 116 | { |
110 | $conf = ConfigManager::getInstance(); | 117 | if (is_file($this->conf->get('path.data_dir') . '/options.php')) { |
111 | 118 | include $this->conf->get('path.data_dir') . '/options.php'; | |
112 | if (is_file($conf->get('path.data_dir') . '/options.php')) { | ||
113 | include $conf->get('path.data_dir') . '/options.php'; | ||
114 | 119 | ||
115 | // Load GLOBALS into config | 120 | // Load GLOBALS into config |
116 | $allowedKeys = array_merge(ConfigPhp::$ROOT_KEYS); | 121 | $allowedKeys = array_merge(ConfigPhp::$ROOT_KEYS); |
117 | $allowedKeys[] = 'config'; | 122 | $allowedKeys[] = 'config'; |
118 | foreach ($GLOBALS as $key => $value) { | 123 | foreach ($GLOBALS as $key => $value) { |
119 | if (in_array($key, $allowedKeys)) { | 124 | if (in_array($key, $allowedKeys)) { |
120 | $conf->set($key, $value); | 125 | $this->conf->set($key, $value); |
121 | } | 126 | } |
122 | } | 127 | } |
123 | $conf->write($this->isLoggedIn); | 128 | $this->conf->write($this->isLoggedIn); |
124 | unlink($conf->get('path.data_dir').'/options.php'); | 129 | unlink($this->conf->get('path.data_dir').'/options.php'); |
125 | } | 130 | } |
126 | 131 | ||
127 | return true; | 132 | return true; |
@@ -132,14 +137,13 @@ class Updater | |||
132 | */ | 137 | */ |
133 | public function updateMethodRenameDashTags() | 138 | public function updateMethodRenameDashTags() |
134 | { | 139 | { |
135 | $conf = ConfigManager::getInstance(); | ||
136 | $linklist = $this->linkDB->filterSearch(); | 140 | $linklist = $this->linkDB->filterSearch(); |
137 | foreach ($linklist as $link) { | 141 | foreach ($linklist as $link) { |
138 | $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']); | 142 | $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']); |
139 | $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); | 143 | $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); |
140 | $this->linkDB[$link['linkdate']] = $link; | 144 | $this->linkDB[$link['linkdate']] = $link; |
141 | } | 145 | } |
142 | $this->linkDB->savedb($conf->get('path.page_cache')); | 146 | $this->linkDB->savedb($this->conf->get('path.page_cache')); |
143 | return true; | 147 | return true; |
144 | } | 148 | } |
145 | 149 | ||
@@ -151,23 +155,21 @@ class Updater | |||
151 | */ | 155 | */ |
152 | public function updateMethodConfigToJson() | 156 | public function updateMethodConfigToJson() |
153 | { | 157 | { |
154 | $conf = ConfigManager::getInstance(); | ||
155 | |||
156 | // JSON config already exists, nothing to do. | 158 | // JSON config already exists, nothing to do. |
157 | if ($conf->getConfigIO() instanceof ConfigJson) { | 159 | if ($this->conf->getConfigIO() instanceof ConfigJson) { |
158 | return true; | 160 | return true; |
159 | } | 161 | } |
160 | 162 | ||
161 | $configPhp = new ConfigPhp(); | 163 | $configPhp = new ConfigPhp(); |
162 | $configJson = new ConfigJson(); | 164 | $configJson = new ConfigJson(); |
163 | $oldConfig = $configPhp->read($conf::$CONFIG_FILE . '.php'); | 165 | $oldConfig = $configPhp->read($this->conf->getConfigFile() . '.php'); |
164 | rename($conf->getConfigFile(), $conf::$CONFIG_FILE . '.save.php'); | 166 | rename($this->conf->getConfigFileExt(), $this->conf->getConfigFile() . '.save.php'); |
165 | $conf->setConfigIO($configJson); | 167 | $this->conf->setConfigIO($configJson); |
166 | $conf->reload(); | 168 | $this->conf->reload(); |
167 | 169 | ||
168 | $legacyMap = array_flip(ConfigPhp::$LEGACY_KEYS_MAPPING); | 170 | $legacyMap = array_flip(ConfigPhp::$LEGACY_KEYS_MAPPING); |
169 | foreach (ConfigPhp::$ROOT_KEYS as $key) { | 171 | foreach (ConfigPhp::$ROOT_KEYS as $key) { |
170 | $conf->set($legacyMap[$key], $oldConfig[$key]); | 172 | $this->conf->set($legacyMap[$key], $oldConfig[$key]); |
171 | } | 173 | } |
172 | 174 | ||
173 | // Set sub config keys (config and plugins) | 175 | // Set sub config keys (config and plugins) |
@@ -179,12 +181,12 @@ class Updater | |||
179 | } else { | 181 | } else { |
180 | $configKey = $sub .'.'. $key; | 182 | $configKey = $sub .'.'. $key; |
181 | } | 183 | } |
182 | $conf->set($configKey, $value); | 184 | $this->conf->set($configKey, $value); |
183 | } | 185 | } |
184 | } | 186 | } |
185 | 187 | ||
186 | try{ | 188 | try{ |
187 | $conf->write($this->isLoggedIn); | 189 | $this->conf->write($this->isLoggedIn); |
188 | return true; | 190 | return true; |
189 | } catch (IOException $e) { | 191 | } catch (IOException $e) { |
190 | error_log($e->getMessage()); | 192 | error_log($e->getMessage()); |
@@ -202,12 +204,11 @@ class Updater | |||
202 | */ | 204 | */ |
203 | public function escapeUnescapedConfig() | 205 | public function escapeUnescapedConfig() |
204 | { | 206 | { |
205 | $conf = ConfigManager::getInstance(); | ||
206 | try { | 207 | try { |
207 | $conf->set('general.title', escape($conf->get('general.title'))); | 208 | $this->conf->set('general.title', escape($this->conf->get('general.title'))); |
208 | $conf->set('general.header_link', escape($conf->get('general.header_link'))); | 209 | $this->conf->set('general.header_link', escape($this->conf->get('general.header_link'))); |
209 | $conf->set('extras.redirector', escape($conf->get('extras.redirector'))); | 210 | $this->conf->set('extras.redirector', escape($this->conf->get('extras.redirector'))); |
210 | $conf->write($this->isLoggedIn); | 211 | $this->conf->write($this->isLoggedIn); |
211 | } catch (Exception $e) { | 212 | } catch (Exception $e) { |
212 | error_log($e->getMessage()); | 213 | error_log($e->getMessage()); |
213 | return false; | 214 | return false; |