This commit is contained in:
Marcin Kurczewski 2013-10-18 00:31:22 +02:00
parent 019e7eea7f
commit 5d51297c16
2 changed files with 79 additions and 5 deletions

View file

@ -0,0 +1,74 @@
<?php
require_once __DIR__ . '/../src/core.php';
function usage()
{
echo 'Usage: ' . basename(__FILE__);
echo ' -print|-purge|-move DIR' . PHP_EOL;
return true;
}
array_shift($argv);
if (empty($argv))
usage() and die;
$action = array_shift($argv);
switch ($action)
{
case '-print':
$func = function($name)
{
echo $name . PHP_EOL;
};
break;
case '-move':
if (empty($argv))
usage() and die;
$dir = array_shift($argv);
if (!file_exists($dir))
mkdir($dir, 0755, true);
if (!is_dir($dir))
die($dir . ' is not a dir' . PHP_EOL);
$func = function($name) use ($dir)
{
echo $name . PHP_EOL;
static $filesPath = null;
if ($filesPath == null)
$filesPath = configFactory()->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);
}
}

View file

@ -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);