From ea4c7fac6e8aadd230b8b344ee77d1fb40d006d3 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 30 Oct 2013 22:38:59 +0100 Subject: [PATCH] Added script for CLI post search Other updates include removing unnecessary context retrieval and making post query builder CLI friendly. --- lib/chibi-core | 2 +- scripts/find-posts.php | 28 ++++++++++++++++++++++++++ src/Helpers/PrivilegesHelper.php | 6 ++++++ src/Models/Model_Post_QueryBuilder.php | 4 +--- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 scripts/find-posts.php diff --git a/lib/chibi-core b/lib/chibi-core index dae26a24..beeb483b 160000 --- a/lib/chibi-core +++ b/lib/chibi-core @@ -1 +1 @@ -Subproject commit dae26a24c48a5140175ef7d0843b6b762692b8cd +Subproject commit beeb483bbeef8102fb54f7197d693b0934f063e1 diff --git a/scripts/find-posts.php b/scripts/find-posts.php new file mode 100644 index 00000000..0744c735 --- /dev/null +++ b/scripts/find-posts.php @@ -0,0 +1,28 @@ +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; +} diff --git a/src/Helpers/PrivilegesHelper.php b/src/Helpers/PrivilegesHelper.php index 2cb7bb64..f058ac5d 100644 --- a/src/Helpers/PrivilegesHelper.php +++ b/src/Helpers/PrivilegesHelper.php @@ -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) { diff --git a/src/Models/Model_Post_QueryBuilder.php b/src/Models/Model_Post_QueryBuilder.php index 8fa19d02..afcec60f 100644 --- a/src/Models/Model_Post_QueryBuilder.php +++ b/src/Models/Model_Post_QueryBuilder.php @@ -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);