From 8b2d616a88f3e3a971175702acc6f96364b7f8d0 Mon Sep 17 00:00:00 2001 From: Danang Probo Sayekti Date: Thu, 27 Aug 2015 10:17:27 +0700 Subject: [PATCH] Migrate content and draft --- system/admin/views/update.html.php | 9 ++++++++- system/admin/views/updated-to.html.php | 12 ++++-------- system/includes/functions.php | 35 +++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/system/admin/views/update.html.php b/system/admin/views/update.html.php index 0a58922..42b40a6 100644 --- a/system/admin/views/update.html.php +++ b/system/admin/views/update.html.php @@ -32,4 +32,11 @@ if ($updater->able()) { echo '

Read on Github.

'; } -migrate_old_content(); \ No newline at end of file +$files = array(); +$draft = array(); +$files = glob('content/*/blog/*.md', GLOB_NOSORT); +$draft = glob('content/*/draft/*.md', GLOB_NOSORT); + +if (!empty($files) || !empty($draft)) { + migrate_old_content(); +} \ No newline at end of file diff --git a/system/admin/views/updated-to.html.php b/system/admin/views/updated-to.html.php index 16c3997..302a5ca 100644 --- a/system/admin/views/updated-to.html.php +++ b/system/admin/views/updated-to.html.php @@ -1,9 +1,5 @@ -

Updated to -

-

[]

+

Updated to

+

[]

+

-

- - \ No newline at end of file + \ No newline at end of file diff --git a/system/includes/functions.php b/system/includes/functions.php index d1bde00..8f648d1 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -2618,6 +2618,9 @@ function migrate_old_content() $content = array(); $tmp = array(); $files = array(); + $draft = array(); + $dtmp = array(); + $dfiles = array(); $tmp = glob('content/*/blog/*.md', GLOB_NOSORT); if (is_array($tmp)) { @@ -2695,6 +2698,36 @@ function migrate_old_content() unlink('content/views.json'); } - rebuilt_cache('all'); + $dtmp = glob('content/*/draft/*.md', GLOB_NOSORT); + $old = array(); + if (is_array($dtmp)) { + foreach ($dtmp as $dfile) { + $draft[] = $dfile; + } + } + + if(!empty($draft)) { + foreach ($draft as $d => $val) { + $arr = explode('/', $val); + $old[] = 'content/' . $arr[1] . '/draft/'; + $dir = 'content/' . $arr[1] . '/blog/uncategorized/draft/'; + $new = 'content/' . $arr[1] . '/blog/uncategorized/draft/' . $arr[3]; + if (!is_dir($dir)) { + mkdir($dir, 0775, true); + } + $dfiles[] = array($val, $new); + } + foreach ($dfiles as $fd) { + rename($fd[0], $fd[1]); + } + $tt = array(); + $tt = array_unique($old, SORT_REGULAR); + foreach ($tt as $t) { + rmdir($t); + } + } + + rebuilt_cache('all'); + }