Fixed scripts

I haven't updated these in a loooong time...
This commit is contained in:
Marcin Kurczewski 2014-05-17 17:14:58 +02:00
parent 9f99ccd78f
commit ed74a9f470
4 changed files with 28 additions and 30 deletions

View file

@ -1,26 +1,19 @@
<?php <?php
require_once __DIR__ . '/../src/core.php'; require_once __DIR__ . '/../src/core.php';
function usage() Access::disablePrivilegeChecking();
{
echo 'Usage: ' . basename(__FILE__);
echo ' QUERY' . PHP_EOL;
return true;
}
array_shift($argv); array_shift($argv);
if (empty($argv))
usage() and die;
$query = array_shift($argv); $query = array_shift($argv);
$posts = Model_Post::getEntities($query, null, null); $posts = PostSearchService::getEntities($query, null, null);
foreach ($posts as $post) foreach ($posts as $post)
{ {
echo implode("\t", echo implode("\t",
[ [
$post->id, $post->getId(),
$post->name, $post->getName(),
Model_Post::getFullPath($post->name), $post->tryGetWorkingFullPath(),
$post->mimeType, $post->getMimeType(),
]). PHP_EOL; ]). PHP_EOL;
} }

View file

@ -1,6 +1,8 @@
<?php <?php
require_once __DIR__ . '/../src/core.php'; require_once __DIR__ . '/../src/core.php';
Access::disablePrivilegeChecking();
function usage() function usage()
{ {
echo 'Usage: ' . basename(__FILE__); echo 'Usage: ' . basename(__FILE__);
@ -33,7 +35,7 @@ switch ($action)
$func = function($name) use ($dir) $func = function($name) use ($dir)
{ {
echo $name . PHP_EOL; echo $name . PHP_EOL;
$srcPath = Model_Post::getFullPath($name); $srcPath = PostModel::getFullPath($name);
$dstPath = $dir . DS . $name; $dstPath = $dir . DS . $name;
rename($srcPath, $dstPath); rename($srcPath, $dstPath);
}; };
@ -43,7 +45,7 @@ switch ($action)
$func = function($name) $func = function($name)
{ {
echo $name . PHP_EOL; echo $name . PHP_EOL;
$srcPath = Model_Post::getFullPath($name); $srcPath = PostModel::getFullPath($name);
unlink($srcPath); unlink($srcPath);
}; };
break; break;
@ -53,13 +55,13 @@ switch ($action)
} }
$names = []; $names = [];
foreach (R::findAll('post') as $post) foreach (PostSearchService::getEntities(null, null, null) as $post)
{ {
$names []= $post->name; $names []= $post->getName();
} }
$names = array_flip($names); $names = array_flip($names);
$config = getConfig(); $config = Core::getConfig();
foreach (glob(TextHelper::absolutePath($config->main->filesPath) . DS . '*') as $name) foreach (glob(TextHelper::absolutePath($config->main->filesPath) . DS . '*') as $name)
{ {
$name = basename($name); $name = basename($name);

View file

@ -1,6 +1,8 @@
<?php <?php
require_once __DIR__ . '/../src/core.php'; require_once __DIR__ . '/../src/core.php';
Access::disablePrivilegeChecking();
function usage() function usage()
{ {
echo 'Usage: ' . basename(__FILE__); echo 'Usage: ' . basename(__FILE__);
@ -14,10 +16,10 @@ if (empty($argv))
function printUser($user) function printUser($user)
{ {
echo 'ID: ' . $user->id . PHP_EOL; echo 'ID: ' . $user->getId() . PHP_EOL;
echo 'Name: ' . $user->name . PHP_EOL; echo 'Name: ' . $user->getName() . PHP_EOL;
echo 'E-mail: ' . $user->email_unconfirmed . PHP_EOL; echo 'E-mail: ' . $user->getUnconfirmedEmail() . PHP_EOL;
echo 'Date joined: ' . date('Y-m-d H:i:s', $user->join_date) . PHP_EOL; echo 'Date joined: ' . date('Y-m-d H:i:s', $user->getJoinTime()) . PHP_EOL;
echo PHP_EOL; echo PHP_EOL;
} }
@ -32,7 +34,7 @@ switch ($action)
$func = function($user) $func = function($user)
{ {
printUser($user); printUser($user);
Model_User::remove($user); UserModel::remove($user);
}; };
break; break;
@ -40,8 +42,13 @@ switch ($action)
die('Unknown action' . PHP_EOL); die('Unknown action' . PHP_EOL);
} }
$rows = R::find('user', 'email_confirmed IS NULL AND DATETIME(join_date) < DATETIME("now", "-21 days")'); $users = UserSearchService::getEntities(null, null, null);
foreach ($rows as $user) foreach ($users as $user)
{ {
$func($user); if (!$user->getConfirmedEmail()
and !$user->getLastLoginTime()
and ((time() - $user->getJoinTime()) > 21 * 24 * 60 * 60))
{
$func($user);
}
} }

View file

@ -25,10 +25,6 @@ class Access
self::$privileges[$privilegeName][$subPrivilegeName] = $minAccessRank; self::$privileges[$privilegeName][$subPrivilegeName] = $minAccessRank;
} }
//todo: move to scripts etc.
#if (php_sapi_name() == 'cli')
# self::disablePrivilegeChecking();
} }
public static function check(Privilege $privilege, $user = null) public static function check(Privilege $privilege, $user = null)