From 5d51297c16ba0c132a1cdef1aa57f2cd684a20b8 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 18 Oct 2013 00:31:22 +0200 Subject: [PATCH] Closed #42 --- scripts/process-detached-files.php | 74 ++++++++++++++++++++++++++++++ src/core.php | 10 ++-- 2 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 scripts/process-detached-files.php diff --git a/scripts/process-detached-files.php b/scripts/process-detached-files.php new file mode 100644 index 00000000..726078c6 --- /dev/null +++ b/scripts/process-detached-files.php @@ -0,0 +1,74 @@ +main->filesPath; + rename($filesPath . DS . $name, $dir . DS . $name); + }; + break; + + case '-purge': + $func = function($name) use ($dir) + { + echo $name . PHP_EOL; + static $filesPath = null; + if ($filesPath == null) + $filesPath = configFactory()->main->filesPath; + unlink($filesPath . DS . $name); + }; + break; + + default: + die('Unknown action' . PHP_EOL); +} + +$names = []; +foreach (R::findAll('post') as $post) +{ + $names []= $post->name; +} +$names = array_flip($names); + +$config = configFactory(); +$filesPath = $config->main->filesPath; +foreach (glob($filesPath . DS . '*') as $name) +{ + $name = basename($name); + if (!isset($names[$name])) + { + $func($name); + } +} diff --git a/src/core.php b/src/core.php index 231c07d1..476872a8 100644 --- a/src/core.php +++ b/src/core.php @@ -8,10 +8,10 @@ function trueStartTime() } trueStartTime(); -require_once 'lib/php-markdown/Michelf/Markdown.php'; -require_once 'lib/redbean/RedBean/redbean.inc.php'; -require_once 'lib/chibi-core/Facade.php'; -require_once 'lib/chibi-core/Registry.php'; +require_once __DIR__ . '/../lib/php-markdown/Michelf/Markdown.php'; +require_once __DIR__ . '/../lib/redbean/RedBean/redbean.inc.php'; +require_once __DIR__ . '/../lib/chibi-core/Facade.php'; +require_once __DIR__ . '/../lib/chibi-core/Registry.php'; date_default_timezone_set('UTC'); setlocale(LC_CTYPE, 'en_US.UTF-8'); @@ -46,7 +46,7 @@ R::setup('sqlite:' . $config->main->dbPath); R::dependencies(['tag' => ['post'], 'favoritee' => ['post', 'user'], 'comment' => ['post', 'user']]); //wire models -\Chibi\AutoLoader::init([$config->chibi->userCodeDir, __DIR__]); +\Chibi\AutoLoader::init([__DIR__ . '/../' . $config->chibi->userCodeDir, __DIR__]); foreach (\Chibi\AutoLoader::getAllIncludablePaths() as $path) if (preg_match('/Model/', $path)) \Chibi\AutoLoader::safeInclude($path);