diff options
author | Arthur <arthur@hoa.ro> | 2016-12-12 03:15:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-12 03:15:32 +0100 |
commit | 9cf93bcfc53c36e0dd59fcfc717ac483ee74b35a (patch) | |
tree | 505cd68f1d07e0b4d6aedcd49c31368760798c62 /application/Updater.php | |
parent | a0d079141eb155c263ebfaa1aad2629382223e31 (diff) | |
parent | d592daea8343bb4dfecff5d97e93699581ccc58c (diff) | |
download | Shaarli-9cf93bcfc53c36e0dd59fcfc717ac483ee74b35a.tar.gz Shaarli-9cf93bcfc53c36e0dd59fcfc717ac483ee74b35a.tar.zst Shaarli-9cf93bcfc53c36e0dd59fcfc717ac483ee74b35a.zip |
Merge pull request #697 from ArthurHoaro/feature/ids-bis
Link ID refactoring
Diffstat (limited to 'application/Updater.php')
-rw-r--r-- | application/Updater.php | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/application/Updater.php b/application/Updater.php index 36eddd4f..f0d02814 100644 --- a/application/Updater.php +++ b/application/Updater.php | |||
@@ -138,10 +138,10 @@ class Updater | |||
138 | public function updateMethodRenameDashTags() | 138 | public function updateMethodRenameDashTags() |
139 | { | 139 | { |
140 | $linklist = $this->linkDB->filterSearch(); | 140 | $linklist = $this->linkDB->filterSearch(); |
141 | foreach ($linklist as $link) { | 141 | foreach ($linklist as $key => $link) { |
142 | $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']); | 142 | $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']); |
143 | $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); | 143 | $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); |
144 | $this->linkDB[$link['linkdate']] = $link; | 144 | $this->linkDB[$key] = $link; |
145 | } | 145 | } |
146 | $this->linkDB->save($this->conf->get('resource.page_cache')); | 146 | $this->linkDB->save($this->conf->get('resource.page_cache')); |
147 | return true; | 147 | return true; |
@@ -215,6 +215,47 @@ class Updater | |||
215 | } | 215 | } |
216 | return true; | 216 | return true; |
217 | } | 217 | } |
218 | |||
219 | /** | ||
220 | * Update the database to use the new ID system, which replaces linkdate primary keys. | ||
221 | * Also, creation and update dates are now DateTime objects (done by LinkDB). | ||
222 | * | ||
223 | * Since this update is very sensitve (changing the whole database), the datastore will be | ||
224 | * automatically backed up into the file datastore.<datetime>.php. | ||
225 | * | ||
226 | * LinkDB also adds the field 'shorturl' with the precedent format (linkdate smallhash), | ||
227 | * which will be saved by this method. | ||
228 | * | ||
229 | * @return bool true if the update is successful, false otherwise. | ||
230 | */ | ||
231 | public function updateMethodDatastoreIds() | ||
232 | { | ||
233 | // up to date database | ||
234 | if (isset($this->linkDB[0])) { | ||
235 | return true; | ||
236 | } | ||
237 | |||
238 | $save = $this->conf->get('resource.data_dir') .'/datastore.'. date('YmdHis') .'.php'; | ||
239 | copy($this->conf->get('resource.datastore'), $save); | ||
240 | |||
241 | $links = array(); | ||
242 | foreach ($this->linkDB as $offset => $value) { | ||
243 | $links[] = $value; | ||
244 | unset($this->linkDB[$offset]); | ||
245 | } | ||
246 | $links = array_reverse($links); | ||
247 | $cpt = 0; | ||
248 | foreach ($links as $l) { | ||
249 | unset($l['linkdate']); | ||
250 | $l['id'] = $cpt; | ||
251 | $this->linkDB[$cpt++] = $l; | ||
252 | } | ||
253 | |||
254 | $this->linkDB->save($this->conf->get('resource.page_cache')); | ||
255 | $this->linkDB->reorder(); | ||
256 | |||
257 | return true; | ||
258 | } | ||
218 | } | 259 | } |
219 | 260 | ||
220 | /** | 261 | /** |