Files
ops-Gazelle/bin/boris

107 lines
2.9 KiB
PHP
Executable File

#! /usr/bin/env php
<?php
namespace Gazelle;
use Gazelle\Enum\FeaturedAlbumType;
use Gazelle\Enum\LeechType;
use Gazelle\Enum\LeechReason;
error_reporting(E_ALL);
require_once(__DIR__ . '/../lib/bootstrap.php');
require_once(__DIR__ . '/../tests/helper.php');
$remove = [];
foreach (['pcntl_fork', 'pcntl_signal', 'pcntl_signal_dispatch', 'pcntl_waitpid'] as $function) {
if (!function_exists($function)) {
$remove[] = $function;
}
}
if ($remove) {
echo "The following functions must be removed from the `disable_functions` directive in cli/php.ini:\n";
echo "=> ", implode(', ', $remove), "\n";
exit;
}
define('BORIS', 1);
$_SERVER['HTTP_USER_AGENT'] = 'boris';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
Base::setRequestContext(new RequestContext(
'boris', $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']
));
$torMan = new Manager\Torrent();
$userMan = new Manager\User();
$db = DB::DB();
$sysop = $userMan->findById(
$db->scalar('
SELECT um.id
FROM users_main um
INNER JOIN permissions p on (p.ID = um.PermissionID)
ORDER BY p.level DESC
LIMIT 1
')
);
if (!$sysop instanceof User) {
echo "**** NOTE! no viewer context is set\n";
} else {
$sysop->requestContext()->setViewer($sysop);
\Text::setViewer($sysop);
Util\Twig::setViewer($sysop);
echo "** viewer context is @{$sysop->username()}\n";
}
$preload = [
'cache' => $Cache,
'db' => $db,
'debug' => $Debug,
'Twig' => $Twig,
'artMan' => new Manager\Artist(),
'bonus' => new Manager\Bonus(),
'collMan' => new Manager\Collage(),
'forMan' => new Manager\Forum(),
'pg' => new DB\Pg(PG_RO_DSN),
'postMan' => new Manager\ForumPost(),
'privMan' => new Manager\Privilege(),
'repMan' => new Manager\Report($userMan),
'reqMan' => new Manager\Request(),
'tagMan' => new Manager\Tag(),
'tgMan' => new Manager\TGroup(),
'threadMan' => new Manager\ForumThread(),
'torMan' => $torMan,
'trepMan' => new Manager\Torrent\Report($torMan),
'trepTypeMan' => new Manager\Torrent\ReportType(),
'userMan' => $userMan,
'notifMan' => new Manager\Notification(),
];
printf("** preloaded objects:\n** %s\n", implode(', ', array_keys($preload)));
$b = new \Boris\Boris(SITE_NAME . '> ');
$b->setInspector(new \Boris\ExportInspector());
$b->setLocal($preload);
$b->start();
/*
* Sample usage:
*
./boris
[1] ops> $db->query('select count(*) from torrents');
// object(mysqli_result)(
// 'current_field' => NULL,
// 'field_count' => NULL,
// 'lengths' => NULL,
// 'num_rows' => NULL,
// 'type' => NULL
// )
[2] ops> $db->to_array();
// array(
// 0 => array(
// 0 => '14',
// 'count(*)' => '14'
// )
// )
*/