Merge pull request #407 from romainneutron/check-config

[3.8] Add check config command
This commit is contained in:
Romain Neutron
2013-06-17 11:26:27 -07:00
5 changed files with 105 additions and 7 deletions

View File

@@ -5,6 +5,8 @@
- BC Break : Removed `bin/console check:config` command. - BC Break : Removed `bin/console check:config` command.
- BC Break : Removed `bin/console check:system` command, replaced by `bin/setup check:system`. - BC Break : Removed `bin/console check:system` command, replaced by `bin/setup check:system`.
- BC Break : Removed `bin/console system:upgrade` command, replaced by `bin/setup system:upgrade`. - BC Break : Removed `bin/console system:upgrade` command, replaced by `bin/setup system:upgrade`.
- BC Break : Removed `bin/console check:ensure-production-settings` and `bin/console check:ensure-dev-settings`
commands, replaced by `bin/console check:config`.
- BC break : Configuration simplification, optimized for performances. - BC break : Configuration simplification, optimized for performances.
- BC Break : Time limits are now applied on templates application. - BC Break : Time limits are now applied on templates application.

View File

@@ -27,6 +27,7 @@ use Alchemy\Phrasea\Command\UpgradeDBDatas;
use Alchemy\Phrasea\CLI; use Alchemy\Phrasea\CLI;
use Alchemy\Phrasea\Command\Plugin\AddPlugin; use Alchemy\Phrasea\Command\Plugin\AddPlugin;
use Alchemy\Phrasea\Command\Plugin\RemovePlugin; use Alchemy\Phrasea\Command\Plugin\RemovePlugin;
use Alchemy\Phrasea\Command\CheckConfig;
require_once __DIR__ . '/../lib/autoload.php'; require_once __DIR__ . '/../lib/autoload.php';
@@ -60,6 +61,7 @@ try {
$app->command(new \module_console_aboutLicense('about:license')); $app->command(new \module_console_aboutLicense('about:license'));
$app->command(new \module_console_checkExtension('check:extension')); $app->command(new \module_console_checkExtension('check:extension'));
$app->command(new CheckConfig('check:config'));
$app->command(new UpgradeDBDatas('system:upgrade-datas')); $app->command(new UpgradeDBDatas('system:upgrade-datas'));

View File

@@ -0,0 +1,80 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\Phrasea\Setup\Requirements\BinariesRequirements;
use Alchemy\Phrasea\Setup\Requirements\FilesystemRequirements;
use Alchemy\Phrasea\Setup\Requirements\LocalesRequirements;
use Alchemy\Phrasea\Setup\Requirements\PhraseaRequirements;
use Alchemy\Phrasea\Setup\Requirements\PhpRequirements;
use Alchemy\Phrasea\Setup\Requirements\SystemRequirements;
use Alchemy\Phrasea\Command\Setup\CheckEnvironment;
class CheckConfig extends CheckEnvironment
{
const CHECK_OK = 0;
const CHECK_WARNING = 1;
const CHECK_ERROR = 2;
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription("Checks environment");
return $this;
}
/**
* {@inheritdoc}
*/
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$ret = parent::doExecute($input, $output);
foreach ($this->container['phraseanet.appbox']->get_databoxes() as $databox) {
$output->writeln("\nDatabox <info>".$databox->get_viewname()."</info> fields configuration\n");
foreach ($databox->get_meta_structure() as $field) {
if ($field->get_original_source() !== $field->get_tag()->getTagname()) {
$status = ' <comment>WARNING</comment> ';
$info = sprintf(" (Described as '<comment>%s</comment>', this source does not seem to exist)", $field->get_original_source());
} else {
$status = ' <info>OK</info> ';
$info = '';
}
$output->writeln($status.$databox->get_viewname() . "::".$field->get_name().$info);
}
$output->writeln("\n");
}
$output->writeln("\nCache configuration\n");
$cache = str_replace('Alchemy\\Phrasea\\Cache\\', '', get_class($this->container['cache']));
$opCodeCache = str_replace('Alchemy\\Phrasea\\Cache\\', '', get_class($this->container['opcode-cache']));
if ('ArrayCache' === $cache) {
$output->writeln(' <comment>WARNING</comment> Current cache configuration uses <comment>ArrayCache</comment> (Or cache server is unreachable). Please check your cache configuration to use a cache server.');
} else {
$output->writeln(' <info>OK</info> Current cache configuration uses <info>'. $cache .'</info>');
}
if ('ArrayCache' === $opCodeCache) {
$output->writeln(' <comment>WARNING</comment> Current opcode cache configuration uses <comment>ArrayCache</comment>. Please check your cache configuration to use an opcode cache.');
} else {
$output->writeln(' <info>OK</info> Current opcode cache configuration uses <info>'. $opCodeCache .'</info>');
}
return $ret;
}
}

View File

@@ -379,7 +379,7 @@ class Fields implements ControllerProviderInterface
private function validateTagField(array $field) private function validateTagField(array $field)
{ {
try { try {
\databox_field::loadClassFromTagName($field['tag']); \databox_field::loadClassFromTagName($field['tag'], true);
} catch (\Exception_Databox_metadataDescriptionNotFound $e) { } catch (\Exception_Databox_metadataDescriptionNotFound $e) {
throw new BadRequestHttpException(_(sprintf('Provided tag %s is unknown.', $field['tag']))); throw new BadRequestHttpException(_(sprintf('Provided tag %s is unknown.', $field['tag'])));
} }

View File

@@ -143,6 +143,7 @@ class databox_field implements cache_cacheableInterface
protected $Vocabulary; protected $Vocabulary;
protected $VocabularyRestriction = false; protected $VocabularyRestriction = false;
protected $on_error = false; protected $on_error = false;
protected $original_src;
const TYPE_TEXT = "text"; const TYPE_TEXT = "text";
const TYPE_DATE = "date"; const TYPE_DATE = "date";
@@ -200,7 +201,8 @@ class databox_field implements cache_cacheableInterface
$this->id = (int) $id; $this->id = (int) $id;
$this->tag = self::loadClassFromTagName($row['src']); $this->original_src = $row['src'];
$this->tag = self::loadClassFromTagName($row['src'], false);
if ($row['src'] != $this->tag->getTagname()) { if ($row['src'] != $this->tag->getTagname()) {
$this->on_error = true; $this->on_error = true;
@@ -315,6 +317,11 @@ class databox_field implements cache_cacheableInterface
return $this->databox->get_connection(); return $this->databox->get_connection();
} }
public function get_original_source()
{
return $this->original_src;
}
/** /**
* *
* @return databox * @return databox
@@ -527,7 +534,7 @@ class databox_field implements cache_cacheableInterface
* @return \PHPExiftool\Driver\Tag * @return \PHPExiftool\Driver\Tag
* @throws Exception_Databox_metadataDescriptionNotFound * @throws Exception_Databox_metadataDescriptionNotFound
*/ */
public static function loadClassFromTagName($tagName) public static function loadClassFromTagName($tagName, $throwException = true)
{ {
$tagName = str_replace('/rdf:rdf/rdf:description/', '', $tagName); $tagName = str_replace('/rdf:rdf/rdf:description/', '', $tagName);
@@ -545,16 +552,23 @@ class databox_field implements cache_cacheableInterface
$classname = '\\Alchemy\\Phrasea\\Metadata\\Tag\\' . $tagName; $classname = '\\Alchemy\\Phrasea\\Metadata\\Tag\\' . $tagName;
if ( ! class_exists($classname)) { if ( ! class_exists($classname)) {
if ($throwException) {
throw new Exception_Databox_metadataDescriptionNotFound(sprintf("tagname %s not found", $tagName)); throw new Exception_Databox_metadataDescriptionNotFound(sprintf("tagname %s not found", $tagName));
} else {
$tag = new Alchemy\Phrasea\Metadata\Tag\Nosource();
} }
} else {
$tag = new $classname(); $tag = new $classname();
}
} else { } else {
try { try {
$tag = TagFactory::getFromRDFTagname($tagName); $tag = TagFactory::getFromRDFTagname($tagName);
} catch (TagUnknown $e) { } catch (TagUnknown $e) {
if ($throwException) {
throw new NotFoundHttpException(sprintf("Tag %s not found", $tagName), $e); throw new NotFoundHttpException(sprintf("Tag %s not found", $tagName), $e);
} }
$tag = new Alchemy\Phrasea\Metadata\Tag\Nosource();
}
} }
return $tag; return $tag;