Added script for CLI post search
Other updates include removing unnecessary context retrieval and making post query builder CLI friendly.
This commit is contained in:
parent
1714e9e665
commit
ea4c7fac6e
4 changed files with 36 additions and 4 deletions
|
@ -1 +1 @@
|
|||
Subproject commit dae26a24c48a5140175ef7d0843b6b762692b8cd
|
||||
Subproject commit beeb483bbeef8102fb54f7197d693b0934f063e1
|
28
scripts/find-posts.php
Normal file
28
scripts/find-posts.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../src/core.php';
|
||||
\Chibi\Registry::setConfig(configFactory());
|
||||
|
||||
function usage()
|
||||
{
|
||||
echo 'Usage: ' . basename(__FILE__);
|
||||
echo ' QUERY' . PHP_EOL;
|
||||
return true;
|
||||
}
|
||||
|
||||
array_shift($argv);
|
||||
if (empty($argv))
|
||||
usage() and die;
|
||||
|
||||
$filesPath = rtrim(\Chibi\Registry::getConfig()->main->filesPath, DS);
|
||||
$query = array_shift($argv);
|
||||
$posts = Model_Post::getEntities($query, null, null);
|
||||
foreach ($posts as $post)
|
||||
{
|
||||
echo implode("\t",
|
||||
[
|
||||
$post->id,
|
||||
$post->name,
|
||||
$filesPath . DS . $post->name,
|
||||
$post->mimeType,
|
||||
]). PHP_EOL;
|
||||
}
|
|
@ -22,6 +22,9 @@ class PrivilegesHelper
|
|||
|
||||
public static function confirm($privilege, $subPrivilege = null)
|
||||
{
|
||||
if (php_sapi_name() == 'cli')
|
||||
return true;
|
||||
|
||||
$user = \Chibi\Registry::getContext()->user;
|
||||
$minAccessRank = AccessRank::Admin;
|
||||
|
||||
|
@ -66,6 +69,9 @@ class PrivilegesHelper
|
|||
|
||||
public static function getAllowedSafety()
|
||||
{
|
||||
if (php_sapi_name() == 'cli')
|
||||
return PostSafety::getAll();
|
||||
|
||||
$context = \Chibi\Registry::getContext();
|
||||
return array_filter(PostSafety::getAll(), function($safety) use ($context)
|
||||
{
|
||||
|
|
|
@ -30,7 +30,6 @@ class Model_Post_QueryBuilder implements AbstractQueryBuilder
|
|||
|
||||
protected static function filterUserSafety($dbQuery)
|
||||
{
|
||||
$context = \Chibi\Registry::getContext();
|
||||
$allowedSafety = PrivilegesHelper::getAllowedSafety();
|
||||
$dbQuery->addSql('safety')->in('(' . R::genSlots($allowedSafety) . ')');
|
||||
foreach ($allowedSafety as $s)
|
||||
|
@ -295,7 +294,7 @@ class Model_Post_QueryBuilder implements AbstractQueryBuilder
|
|||
throw new SimpleException('Unknown key "' . $val . '"');
|
||||
}
|
||||
|
||||
if ($randomReset)
|
||||
if ($randomReset and isset($_SESSION['browsing-seed']))
|
||||
unset($_SESSION['browsing-seed']);
|
||||
|
||||
$dbQuery->orderBy($orderColumn);
|
||||
|
@ -310,7 +309,6 @@ class Model_Post_QueryBuilder implements AbstractQueryBuilder
|
|||
public static function build($dbQuery, $query)
|
||||
{
|
||||
$config = \Chibi\Registry::getConfig();
|
||||
$context = \Chibi\Registry::getContext();
|
||||
|
||||
self::attachCommentCount($dbQuery);
|
||||
self::attachFavCount($dbQuery);
|
||||
|
|
Loading…
Reference in a new issue