X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FUpdater.php;h=f0d02814b5599654b0c6638e40e02e86068a5ab7;hb=d592daea8343bb4dfecff5d97e93699581ccc58c;hp=90913235ca8e528d22d8103288971a787fcf08ef;hpb=7af9a41881ed0b9d44d18a0ce03a123a8441adf5;p=github%2Fshaarli%2FShaarli.git diff --git a/application/Updater.php b/application/Updater.php index 90913235..f0d02814 100644 --- a/application/Updater.php +++ b/application/Updater.php @@ -138,12 +138,12 @@ class Updater public function updateMethodRenameDashTags() { $linklist = $this->linkDB->filterSearch(); - foreach ($linklist as $link) { + foreach ($linklist as $key => $link) { $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']); $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); - $this->linkDB[$link['linkdate']] = $link; + $this->linkDB[$key] = $link; } - $this->linkDB->savedb($this->conf->get('resource.page_cache')); + $this->linkDB->save($this->conf->get('resource.page_cache')); return true; } @@ -215,6 +215,47 @@ class Updater } return true; } + + /** + * Update the database to use the new ID system, which replaces linkdate primary keys. + * Also, creation and update dates are now DateTime objects (done by LinkDB). + * + * Since this update is very sensitve (changing the whole database), the datastore will be + * automatically backed up into the file datastore..php. + * + * LinkDB also adds the field 'shorturl' with the precedent format (linkdate smallhash), + * which will be saved by this method. + * + * @return bool true if the update is successful, false otherwise. + */ + public function updateMethodDatastoreIds() + { + // up to date database + if (isset($this->linkDB[0])) { + return true; + } + + $save = $this->conf->get('resource.data_dir') .'/datastore.'. date('YmdHis') .'.php'; + copy($this->conf->get('resource.datastore'), $save); + + $links = array(); + foreach ($this->linkDB as $offset => $value) { + $links[] = $value; + unset($this->linkDB[$offset]); + } + $links = array_reverse($links); + $cpt = 0; + foreach ($links as $l) { + unset($l['linkdate']); + $l['id'] = $cpt; + $this->linkDB[$cpt++] = $l; + } + + $this->linkDB->save($this->conf->get('resource.page_cache')); + $this->linkDB->reorder(); + + return true; + } } /**