2013-10-18 00:31:22 +02:00
|
|
|
<?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);
|
2013-11-23 20:52:41 +01:00
|
|
|
$func = function($name) use ($dir)
|
2013-10-18 00:31:22 +02:00
|
|
|
{
|
|
|
|
echo $name . PHP_EOL;
|
2013-11-23 20:52:41 +01:00
|
|
|
$srcPath = Model_Post::getFullPath($name);
|
|
|
|
$dstPath = $dir . DS . $name;
|
|
|
|
rename($srcPath, $dstPath);
|
2013-10-18 00:31:22 +02:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '-purge':
|
2013-11-23 20:52:41 +01:00
|
|
|
$func = function($name)
|
2013-10-18 00:31:22 +02:00
|
|
|
{
|
|
|
|
echo $name . PHP_EOL;
|
2013-11-23 20:52:41 +01:00
|
|
|
$srcPath = Model_Post::getFullPath($name);
|
|
|
|
unlink($srcPath);
|
2013-10-18 00:31:22 +02:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
die('Unknown action' . PHP_EOL);
|
|
|
|
}
|
|
|
|
|
|
|
|
$names = [];
|
|
|
|
foreach (R::findAll('post') as $post)
|
|
|
|
{
|
|
|
|
$names []= $post->name;
|
|
|
|
}
|
|
|
|
$names = array_flip($names);
|
|
|
|
|
2013-11-23 20:52:41 +01:00
|
|
|
$config = \Chibi\Registry::getConfig();
|
|
|
|
foreach (glob(TextHelper::absolutePath($config->main->filesPath) . DS . '*') as $name)
|
2013-10-18 00:31:22 +02:00
|
|
|
{
|
|
|
|
$name = basename($name);
|
|
|
|
if (!isset($names[$name]))
|
|
|
|
{
|
|
|
|
$func($name);
|
|
|
|
}
|
|
|
|
}
|