#!/usr/bin/env php
<?php

/**
 * @package Newscoop\NewscoopBundle
 * @author Paweł Mikołajczuk <pawel.mikolajczuk@sourcefabric.org>
 * @copyright 2012 Sourcefabric o.p.s.
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 */

global $g_ado_db;

// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);

set_time_limit(0);
define('APPLICATION_ENV', 'cli');

require_once __DIR__ . '/../constants.php';
require_once __DIR__ . '/bootstrap.php.cache';
require_once __DIR__ . '/AppKernel.php';

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;

error_reporting(error_reporting() & ~E_STRICT & ~E_DEPRECATED);

$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'prod');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';

if ($debug) {
    Debug::enable();
}

$kernel = new AppKernel($env, $debug);
$cli = new Application($kernel);

$kernel->boot();
$container = $kernel->getContainer();
\Zend_Registry::set('container', $container);

$cli->addCommands(array(
    new \Newscoop\Tools\Console\Command\UpdateIngestCommand(),
    new \Newscoop\Tools\Console\Command\LogMaintenanceCommand(),
    new \Newscoop\Tools\Console\Command\SendStatsCommand(),
    new \Newscoop\Tools\Console\Command\UpdateImageStorageCommand(),
    new \Newscoop\Tools\Console\Command\UpdateAutoloadCommand(),
    new \Newscoop\Tools\Console\Command\UpdateIndexCommand(),
    new \Newscoop\Tools\Console\Command\ClearIndexCommand(),
    new \Newscoop\Tools\Console\Command\InstallPluginCommand(),
    new \Newscoop\Tools\Console\Command\RemovePluginCommand(),
    new \Newscoop\Tools\Console\Command\UpdatePluginCommand(),
    new \Newscoop\Tools\Console\Command\DispatchEventForPluginCommand(),
    new \Newscoop\Tools\Console\Command\UpgradePluginsCommand(),
    new \Newscoop\Tools\Console\Command\ReloadRenditionsCommand(),
    new \Newscoop\Tools\Console\Command\GenerateWebcodeCommand(),
    new \Newscoop\Tools\Console\Command\InstallNewscoopCommand(),
    new \Newscoop\Tools\Console\Command\CreateOAuthClientCommand(),
    new \Newscoop\Tools\Console\Command\GenerateORMSchemaCommand(),
    new \Newscoop\Tools\Console\Command\UserGarbageCollectionCommand(),
    new \Newscoop\Tools\Console\Command\AutopublishCommand(),
    new \Newscoop\Tools\Console\Command\ClearOldStatisticsCommand(),
    new \Newscoop\Tools\Console\Command\IndexerCommand(),
    new \Newscoop\Tools\Console\Command\EventsNotifierCommand(),
    new \Newscoop\Tools\Console\Command\SubscriptionsNotifierCommand(),
    new \Newscoop\Tools\Console\Command\AssignThemeCommand(),
    new \Newscoop\Tools\Console\Command\SchedulerManagerCommand(),
));

$cli->run($input);
