mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 14:03:27 +00:00
Merge with Scheduler 2 branch
This commit is contained in:
@@ -37,9 +37,9 @@ class module_console_aboutAuthors extends Command
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln(file_get_contents(dirname(__FILE__) . '/../../../../AUTHORS'));
|
||||
$output->writeln(file_get_contents(__DIR__ . '/../../../../AUTHORS'));
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -37,9 +37,9 @@ class module_console_aboutLicense extends Command
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln(file_get_contents(dirname(__FILE__) . '/../../../../LICENSE'));
|
||||
$output->writeln(file_get_contents(__DIR__ . '/../../../../LICENSE'));
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
248
lib/classes/module/console/checkExtension.class.php
Normal file
248
lib/classes/module/console/checkExtension.class.php
Normal file
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_checkExtension extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Delete a documentation field from a Databox');
|
||||
|
||||
$this->addOption('usr_id', 'u', InputOption::VALUE_OPTIONAL, 'Usr_id to use. If no user, get the first available');
|
||||
|
||||
$this->addOption('query', '', InputOption::VALUE_OPTIONAL, 'The query', 'last');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
if (!extension_loaded('phrasea2'))
|
||||
printf("Missing Extension php-phrasea");
|
||||
|
||||
$appbox = \appbox::get_instance();
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
$usr_id = $input->getOption('usr_id');
|
||||
|
||||
try
|
||||
{
|
||||
$TestUser = \User_Adapter::getInstance($usr_id, $appbox);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Wrong user !</error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"\nWill do the check with user <info>%s</info> (%s)\n"
|
||||
, $TestUser->get_display_name()
|
||||
, $TestUser->get_email()
|
||||
)
|
||||
);
|
||||
|
||||
$output->writeln("PHRASEA FUNCTIONS");
|
||||
|
||||
foreach (get_extension_funcs("phrasea2") as $function)
|
||||
{
|
||||
$output->writeln("<info>$function</info>");
|
||||
}
|
||||
|
||||
require (__DIR__ . '/../../../../config/connexion.inc');
|
||||
|
||||
|
||||
$output->writeln("\n-- phrasea_conn --");
|
||||
|
||||
if (phrasea_conn($hostname, $port, $user, $password, $dbname) !== true)
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> got no connection");
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got connection");
|
||||
}
|
||||
|
||||
$output->writeln("");
|
||||
|
||||
$output->writeln("\n-- phrasea_info --");
|
||||
|
||||
foreach (phrasea_info() as $key => $value)
|
||||
{
|
||||
$output->writeln("\t$key => $value");
|
||||
}
|
||||
|
||||
|
||||
$output->writeln("");
|
||||
|
||||
$output->writeln("\n-- phrasea_create_session --");
|
||||
|
||||
$sessid = phrasea_create_session((string) $TestUser->get_id());
|
||||
|
||||
if (ctype_digit((string) $sessid))
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got session id $sessid");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> got no session id");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("\n-- phrasea_open_session --");
|
||||
|
||||
$ph_session = phrasea_open_session($sessid, $usr_id);
|
||||
|
||||
if ($ph_session)
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got session ");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> got no session ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("\n-- phrasea_clear_cache --");
|
||||
|
||||
$ret = phrasea_clear_cache($sessid);
|
||||
|
||||
if ($sessid)
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got session ");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> got no session ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$tbases = array();
|
||||
|
||||
foreach ($ph_session["bases"] as $phbase)
|
||||
{
|
||||
$tcoll = array();
|
||||
foreach ($phbase["collections"] as $coll)
|
||||
{
|
||||
$tcoll[] = 0 + $coll["base_id"];
|
||||
}
|
||||
if (sizeof($tcoll) > 0)
|
||||
{
|
||||
$kbase = "S" . $phbase["sbas_id"];
|
||||
$tbases[$kbase] = array();
|
||||
$tbases[$kbase]["sbas_id"] = $phbase["sbas_id"];
|
||||
$tbases[$kbase]["searchcoll"] = $tcoll;
|
||||
$tbases[$kbase]["mask_xor"] = $tbases[$kbase]["mask_and"] = 0;
|
||||
|
||||
$qp = new searchEngine_adapter_phrasea_queryParser();
|
||||
$treeq = $qp->parsequery($input->getOption('query'));
|
||||
$arrayq = $qp->makequery($treeq);
|
||||
|
||||
$tbases[$kbase]["arrayq"] = $arrayq;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$output->writeln("\n-- phrasea_query --");
|
||||
|
||||
$nbanswers = 0;
|
||||
foreach ($tbases as $kb => $base)
|
||||
{
|
||||
$tbases[$kb]["results"] = NULL;
|
||||
|
||||
$ret = phrasea_query2(
|
||||
$ph_session["session_id"]
|
||||
, $base["sbas_id"]
|
||||
, $base["searchcoll"]
|
||||
, $base["arrayq"]
|
||||
, $registry->get('GV_sit')
|
||||
, $usr_id
|
||||
, FALSE
|
||||
, PHRASEA_MULTIDOC_DOCONLY
|
||||
);
|
||||
|
||||
|
||||
if ($ret)
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got result on sbas_id " . $base["sbas_id"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> No results on sbas_id " . $base["sbas_id"]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$tbases[$kb]["results"] = $ret;
|
||||
|
||||
$nbanswers += $tbases[$kb]["results"]["nbanswers"];
|
||||
}
|
||||
|
||||
|
||||
$output->writeln("Got a total of <info>$nbanswers</info> answers");
|
||||
|
||||
$output->writeln("\n-- phrasea_fetch_results --");
|
||||
|
||||
$rs = phrasea_fetch_results($sessid, $usr_id, 1, true, '[[em]]', '[[/em]]');
|
||||
|
||||
if ($rs)
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> got result ");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> got no result ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("\n-- phrasea_close_session --");
|
||||
|
||||
$rs = phrasea_close_session($sessid);
|
||||
|
||||
if ($rs)
|
||||
{
|
||||
$output->writeln("<info>Succes ! </info> closed ! ");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("<error>Failed ! </error> not closed ");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
98
lib/classes/module/console/fieldsDelete.class.php
Normal file
98
lib/classes/module/console/fieldsDelete.class.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_fieldsDelete extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Delete a documentation field from a Databox');
|
||||
|
||||
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id');
|
||||
|
||||
$this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
if (!$input->getOption('sbas_id'))
|
||||
throw new \Exception('Missing argument sbas_id');
|
||||
|
||||
if (!$input->getOption('meta_struct_id'))
|
||||
throw new \Exception('Missing argument meta_struct_id');
|
||||
|
||||
try
|
||||
{
|
||||
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Invalid databox id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$field = $databox->get_meta_structure()->get_element((int) $input->getOption('meta_struct_id'));
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Invalid meta struct id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
$continue = mb_strtolower(
|
||||
$dialog->ask(
|
||||
$output
|
||||
, "<question>About to delete " . $field->get_name() . " (y/N)</question>"
|
||||
, 'n'
|
||||
)
|
||||
);
|
||||
|
||||
if($continue != 'y')
|
||||
{
|
||||
$output->writeln("Request canceled by user");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("Deleting ... ");
|
||||
|
||||
$field->delete();
|
||||
|
||||
$output->writeln("Done with success !");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
70
lib/classes/module/console/fieldsList.class.php
Normal file
70
lib/classes/module/console/fieldsList.class.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_fieldsList extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('List all databox fields');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
{
|
||||
/* @var $databox \databox */
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"\n ---------------- \nOn databox %s (sbas_id %d) :\n"
|
||||
, $databox->get_viewname()
|
||||
, $databox->get_sbas_id()
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($databox->get_meta_structure()->get_elements() as $field)
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
" %2d - <info>%s</info> (%s) %s"
|
||||
, $field->get_id()
|
||||
, $field->get_name()
|
||||
, $field->get_type()
|
||||
, ($field->is_multi() ? '<comment>multi</comment>' : '')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
284
lib/classes/module/console/fieldsMerge.class.php
Normal file
284
lib/classes/module/console/fieldsMerge.class.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_fieldsMerge extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Merge databox structure fields');
|
||||
|
||||
$this->addOption(
|
||||
'source'
|
||||
, 'f'
|
||||
, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
, 'Metadata structure ids for source'
|
||||
, array()
|
||||
);
|
||||
|
||||
$this->addOption(
|
||||
'destination'
|
||||
, 'd'
|
||||
, InputOption::VALUE_REQUIRED
|
||||
, 'Metadata structure id destination'
|
||||
);
|
||||
|
||||
$this->addOption(
|
||||
'sbas_id'
|
||||
, 's'
|
||||
, InputOption::VALUE_REQUIRED
|
||||
, 'Databox sbas_id'
|
||||
);
|
||||
|
||||
$this->addOption(
|
||||
'separator'
|
||||
, ''
|
||||
, InputOption::VALUE_OPTIONAL
|
||||
, 'Separator for concatenation (if destination is monovalued)'
|
||||
, ';'
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln("");
|
||||
|
||||
if (!$input->getOption('sbas_id'))
|
||||
throw new \Exception('Missing argument sbas_id');
|
||||
|
||||
try
|
||||
{
|
||||
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Invalid databox id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$sources = array();
|
||||
|
||||
foreach ($input->getOption('source') as $source_id)
|
||||
{
|
||||
$sources[] = $databox->get_meta_structure()->get_element($source_id);
|
||||
}
|
||||
|
||||
if (count($sources) === 0)
|
||||
throw new \Exception('No sources to proceed');
|
||||
|
||||
if (!$input->getOption('destination'))
|
||||
throw new \Exception('Missing argument destination');
|
||||
|
||||
$separator = ' ' . $input->getOption('separator') . ' ';
|
||||
|
||||
$destination = $databox->get_meta_structure()->get_element($input->getOption('destination'));
|
||||
|
||||
$types = $multis = array();
|
||||
|
||||
foreach ($sources as $source)
|
||||
{
|
||||
array_push($types, $source->get_type());
|
||||
array_push($multis, $source->is_multi());
|
||||
}
|
||||
|
||||
$types = array_unique($types);
|
||||
$multis = array_unique($multis);
|
||||
|
||||
if (count(array_unique($types)) > 1)
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf("Warning, trying to merge inconsistent types : <comment>%s</comment>\n"
|
||||
, implode(', ', $types)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (count(array_unique($multis)) > 1)
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"Warning, trying to merge <comment>mono and multi</comment> values fields\n"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$field_names = array();
|
||||
foreach ($sources as $source)
|
||||
{
|
||||
$field_names[] = $source->get_name();
|
||||
}
|
||||
|
||||
if (count($multis) == 1)
|
||||
{
|
||||
if ($multis[0] === false && !$destination->is_multi())
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mono valued fields</info> in a "
|
||||
. "<info>monovalued field</info>, fields will be "
|
||||
. "<comment>concatenated</comment> in the following order : %s"
|
||||
, implode($separator, $field_names)
|
||||
)
|
||||
);
|
||||
$this->displayHelpConcatenation($output);
|
||||
}
|
||||
elseif ($multis[0] === true && !$destination->is_multi())
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>multi valued</info> fields in a "
|
||||
. "<info>monovalued field</info>, fields will be "
|
||||
. "<comment>concatenated</comment> in the following order : %s"
|
||||
, implode(' ', $field_names)
|
||||
)
|
||||
);
|
||||
$this->displayHelpConcatenation($output);
|
||||
}
|
||||
elseif ($multis[0] === false && $destination->is_multi())
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mono valued fields</info> in a "
|
||||
. "<info>multivalued field</info>"
|
||||
)
|
||||
);
|
||||
}
|
||||
elseif ($multis[0] === true && $destination->is_multi())
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>multi valued fields</info> in a "
|
||||
. "<info>multivalued field</info>"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif ($destination->is_multi())
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mixed valued</info> fields in a "
|
||||
. "<info>multivalued</info> field"
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"You are going to merge <info>mixed valued</info> fields in a "
|
||||
. "<info>monovalued field</info>, fields will be "
|
||||
. "<comment>concatenated</comment> in the following order : %s"
|
||||
, implode($separator, $field_names)
|
||||
)
|
||||
);
|
||||
$this->displayHelpConcatenation($output);
|
||||
}
|
||||
|
||||
$start = 0;
|
||||
$quantity = 100;
|
||||
|
||||
do
|
||||
{
|
||||
$sql = 'SELECT record_id FROM record
|
||||
ORDER BY record_id LIMIT ' . $start . ', ' . $quantity;
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($results as $row)
|
||||
{
|
||||
$record = $databox->get_record($row['record_id']);
|
||||
|
||||
$datas = array();
|
||||
|
||||
foreach ($sources as $source)
|
||||
{
|
||||
try
|
||||
{
|
||||
$value = $record->get_caption()->get_field($source->get_name())->get_value();
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$value = array();
|
||||
}
|
||||
if (!is_array($value))
|
||||
{
|
||||
$value = array($value);
|
||||
}
|
||||
|
||||
$datas = array_merge($datas, $value);
|
||||
}
|
||||
|
||||
$datas = array_unique($datas);
|
||||
|
||||
if (!$destination->is_multi())
|
||||
{
|
||||
$datas = array(implode($separator, $datas));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$record->get_caption()->get_field($destination->get_name())->set_value($datas);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$record->set_metadatas(
|
||||
array(
|
||||
array(
|
||||
'meta_struct_id' => $destination->get_id()
|
||||
, 'meta_id' => null
|
||||
, 'value' => $datas
|
||||
)
|
||||
)
|
||||
, true
|
||||
);
|
||||
}
|
||||
unset($record);
|
||||
}
|
||||
|
||||
$start += $quantity;
|
||||
}
|
||||
while (count($results) > 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function displayHelpConcatenation(OutputInterface $output)
|
||||
{
|
||||
|
||||
$output->writeln("\nYou can choose the concatenation order in the "
|
||||
. "commandline (first option is first value) and set a separator "
|
||||
. "with the --separator option)");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
106
lib/classes/module/console/fieldsRename.class.php
Normal file
106
lib/classes/module/console/fieldsRename.class.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_fieldsRename extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Rename a documentation field from a Databox');
|
||||
|
||||
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id');
|
||||
|
||||
$this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id');
|
||||
|
||||
$this->addOption('name', 'n', InputOption::VALUE_REQUIRED, 'The new name');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
if (!$input->getOption('sbas_id'))
|
||||
throw new \Exception('Missing argument sbas_id');
|
||||
|
||||
if (!$input->getOption('meta_struct_id'))
|
||||
throw new \Exception('Missing argument meta_struct_id');
|
||||
|
||||
if (!$input->getOption('name'))
|
||||
throw new \Exception('Missing argument name');
|
||||
|
||||
$new_name = $input->getOption('name');
|
||||
|
||||
try
|
||||
{
|
||||
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Invalid databox id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$field = $databox->get_meta_structure()->get_element((int) $input->getArgument('meta_struct_id'));
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln("<error>Invalid meta struct id </error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
$continue = mb_strtolower(
|
||||
$dialog->ask(
|
||||
$output
|
||||
, "<question>About to rename " . $field->get_name() . " into ".$new_name." (y/N)</question>"
|
||||
, 'n'
|
||||
)
|
||||
);
|
||||
|
||||
if($continue != 'y')
|
||||
{
|
||||
$output->writeln("Request canceled by user");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln("Renaming ... ");
|
||||
|
||||
$field->set_name($new_name);
|
||||
$field->save();
|
||||
|
||||
$output->writeln("Done with success !");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
922
lib/classes/module/console/fileEnsureDevSetting.class.php
Normal file
922
lib/classes/module/console/fileEnsureDevSetting.class.php
Normal file
@@ -0,0 +1,922 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument,
|
||||
Symfony\Component\Console\Input\InputInterface,
|
||||
Symfony\Component\Console\Input\InputOption,
|
||||
Symfony\Component\Console\Output\OutputInterface,
|
||||
Symfony\Component\Console\Command\Command;
|
||||
use Alchemy\Phrasea\Core;
|
||||
use Symfony\Component\Yaml;
|
||||
|
||||
/**
|
||||
* @todo write tests
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_console_fileEnsureDevSetting extends Command
|
||||
{
|
||||
|
||||
const ALERT = 1;
|
||||
const ERROR = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Alchemy\Phrasea\Core\Configuration
|
||||
*/
|
||||
protected $configuration;
|
||||
protected $testSuite = array(
|
||||
'checkPhraseanetScope'
|
||||
, 'checkDatabaseScope'
|
||||
, 'checkTeamplateEngineService'
|
||||
, 'checkOrmService'
|
||||
, 'checkCacheService'
|
||||
, 'checkOpcodeCacheService'
|
||||
);
|
||||
protected $errors = 0;
|
||||
protected $alerts = 0;
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Ensure development settings');
|
||||
|
||||
$this->addArgument('conf', InputArgument::OPTIONAL, 'The file to check', null);
|
||||
$this->addOption('strict', 's', InputOption::VALUE_NONE, 'Wheter to fail on alerts or not');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification();
|
||||
|
||||
$environnement = $input->getArgument('conf');
|
||||
|
||||
$this->configuration = \Alchemy\Phrasea\Core\Configuration::build($specifications, $environnement);
|
||||
|
||||
if (!$this->configuration->isInstalled())
|
||||
{
|
||||
$output->writeln(sprintf("\nPhraseanet is not installed\n"));
|
||||
}
|
||||
|
||||
$this->checkParse($output);
|
||||
$output->writeln(sprintf("Will Ensure Production Settings on <info>%s</info>", $this->configuration->getEnvironnement()));
|
||||
|
||||
$this->runTests($output);
|
||||
|
||||
$retval = $this->errors;
|
||||
if ($input->getOption('strict'))
|
||||
{
|
||||
$retval += $this->alerts;
|
||||
}
|
||||
|
||||
if ($retval > 0)
|
||||
{
|
||||
$output->writeln("\n<error>Some errors found in your conf</error>");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\n<info>Your dev settings are setted correctly ! Enjoy</info>");
|
||||
}
|
||||
$output->writeln('End');
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
private function runTests(OutputInterface $output)
|
||||
{
|
||||
foreach ($this->testSuite as $test)
|
||||
{
|
||||
$display = "";
|
||||
switch ($test)
|
||||
{
|
||||
case 'checkPhraseanetScope' :
|
||||
$display = "Phraseanet Configuration";
|
||||
break;
|
||||
case 'checkDatabaseScope' :
|
||||
$display = "Database";
|
||||
break;
|
||||
case 'checkTeamplateEngineService' :
|
||||
$display = "Template Engine";
|
||||
break;
|
||||
case 'checkOrmService' :
|
||||
$display = "ORM";
|
||||
break;
|
||||
case 'checkCacheService' :
|
||||
$display = "Cache";
|
||||
break;
|
||||
case 'checkOpcodeCacheService' :
|
||||
$display = "Opcode";
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('Unknown test');
|
||||
break;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("\n||| %s", mb_strtoupper($display)));
|
||||
|
||||
call_user_func(array($this, $test), $output);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkParse(OutputInterface $output)
|
||||
{
|
||||
|
||||
if (!$this->configuration->getConfigurations())
|
||||
{
|
||||
throw new \Exception("Unable to load configurations\n");
|
||||
}
|
||||
if (!$this->configuration->getConnexions())
|
||||
{
|
||||
throw new \Exception("Unable to load connexions\n");
|
||||
}
|
||||
if (!$this->configuration->getServices())
|
||||
{
|
||||
throw new \Exception("Unable to load services\n");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function checkCacheService(OutputInterface $output)
|
||||
{
|
||||
$cache = $this->configuration->getCache();
|
||||
|
||||
|
||||
if ($this->probeCacheService($output, $cache))
|
||||
{
|
||||
if ($this->recommendedCacheService($output, $cache, true))
|
||||
{
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<comment>Cache server recommended</comment>';
|
||||
$this->alerts++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$verification = sprintf("\t--> Verify <info>%s</info> : %s", 'MainCache', $work_message);
|
||||
|
||||
|
||||
$this->printConf($output, "\t" . 'service', $cache, false, $verification);
|
||||
$this->verifyCacheOptions($output, $cache);
|
||||
}
|
||||
|
||||
private function checkOpcodeCacheService(OutputInterface $output)
|
||||
{
|
||||
$cache = $this->configuration->getOpcodeCache();
|
||||
|
||||
|
||||
if ($this->probeCacheService($output, $cache))
|
||||
{
|
||||
if ($this->recommendedCacheService($output, $cache, false))
|
||||
{
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<error>No cache required</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$verification = sprintf("\t--> Verify <info>%s</info> : %s", 'OpcodeCache', $work_message);
|
||||
|
||||
|
||||
$this->printConf($output, "\t" . 'service', $cache, false, $verification);
|
||||
$this->verifyCacheOptions($output, $cache);
|
||||
}
|
||||
|
||||
private function checkPhraseanetScope(OutputInterface $output)
|
||||
{
|
||||
$required = array('servername', 'maintenance', 'debug', 'display_errors', 'database');
|
||||
|
||||
$phraseanet = $this->configuration->getPhraseanet();
|
||||
|
||||
foreach ($phraseanet->all() as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, $conf, $value, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
case 'servername':
|
||||
$url = $value;
|
||||
$required = array_diff($required, array($conf));
|
||||
|
||||
$parseUrl = parse_url($url);
|
||||
|
||||
if (empty($url))
|
||||
{
|
||||
$message = "<error>should not be empty</error>";
|
||||
$this->errors++;
|
||||
}
|
||||
elseif ($url == 'http://sub.domain.tld/')
|
||||
{
|
||||
$this->alerts++;
|
||||
$message = "<comment>may be wrong</comment>";
|
||||
}
|
||||
elseif (!filter_var($url, FILTER_VALIDATE_URL))
|
||||
{
|
||||
$message = "<error>not valid</error>";
|
||||
$this->errors++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = "<info>OK</info>";
|
||||
}
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'maintenance':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== false)
|
||||
{
|
||||
$message = '<error>Should be true</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'debug':
|
||||
case 'display_errors':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== true)
|
||||
{
|
||||
$message = '<error>Should be true</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'database':
|
||||
$required = array_diff($required, array($conf));
|
||||
try
|
||||
{
|
||||
$service = $this->configuration->getConnexion($value);
|
||||
if ($this->verifyDatabaseConnexion($service))
|
||||
{
|
||||
$message = '<info>OK</info>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = '<error>Connection not available</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$message = '<error>Unknown connection</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function checkDatabaseScope(OutputInterface $output)
|
||||
{
|
||||
$connexionName = $this->configuration->getPhraseanet()->get('database');
|
||||
$connexion = $this->configuration->getConnexion($connexionName);
|
||||
|
||||
try
|
||||
{
|
||||
if ($this->verifyDatabaseConnexion($connexion))
|
||||
{
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("\t--> Verify connection <info>%s</info> : %s", $connexionName, $work_message));
|
||||
|
||||
$required = array('driver');
|
||||
|
||||
if (!$connexion->has('driver'))
|
||||
{
|
||||
$output->writeln("\n<error>Connection has no driver</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
elseif ($connexion->get('driver') == 'pdo_mysql')
|
||||
{
|
||||
$required = array('driver', 'dbname', 'charset', 'password', 'user', 'port', 'host');
|
||||
}
|
||||
elseif ($connexion->get('driver') == 'pdo_sqlite')
|
||||
{
|
||||
$required = array('driver', 'path', 'charset');
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\n<error>Your driver is not managed</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
foreach ($connexion->all() as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, $conf, $value, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
case 'charset':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
if ($value !== 'UTF8')
|
||||
{
|
||||
$message = '<comment>Not recognized</comment>';
|
||||
$this->alerts++;
|
||||
}
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'path':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = is_writable(dirname($value)) ? '<info>OK</info>' : '<error>Not writeable</error>';
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'dbname':
|
||||
case 'user':
|
||||
case 'host':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_scalar($value))
|
||||
{
|
||||
$message = '<error>Should be scalar</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'port':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!ctype_digit($value))
|
||||
{
|
||||
$message = '<error>Should be ctype_digit</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'password':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_scalar($value))
|
||||
{
|
||||
$message = '<error>Should be scalar</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$value = '***********';
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'driver':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== 'pdo_mysql')
|
||||
{
|
||||
$message = '<error>MySQL recommended</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function verifyDatabaseConnexion(\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag $connexion)
|
||||
{
|
||||
try
|
||||
{
|
||||
$config = new \Doctrine\DBAL\Configuration();
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($connexion->all(), $config);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkTeamplateEngineService(OutputInterface $output)
|
||||
{
|
||||
$templateEngineName = $this->configuration->getTemplating();
|
||||
$configuration = $this->configuration->getService($templateEngineName);
|
||||
|
||||
try
|
||||
{
|
||||
Core\Service\Builder::create(\bootstrap::getCore(), $configuration);
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$work_message = '<error>Failed - could not load template engine !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("\t--> Verify Template engine <info>%s</info> : %s", $templateEngineName, $work_message));
|
||||
|
||||
if (!$configuration->has('type'))
|
||||
{
|
||||
$output->writeln("\n<error>Configuration has no type</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
elseif ($configuration->get('type') == 'TemplateEngine\\Twig')
|
||||
{
|
||||
$required = array('debug', 'charset', 'strict_variables', 'autoescape', 'optimizer');
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\n<error>Your type is not managed</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach ($configuration->all() as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
case 'type':
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== 'TemplateEngine\\Twig')
|
||||
{
|
||||
$message = '<error>Not recognized</error>';
|
||||
$this->alerts++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'options':
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
$message = '<error>Should be array</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, 'array()', false, $message);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, $conf, 'unknown', false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($configuration->get('options') as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
case 'debug';
|
||||
case 'strict_variables';
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== true)
|
||||
{
|
||||
$message = '<error>Should be false</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, "\t" . $conf, $value, false, $message);
|
||||
break;
|
||||
case 'autoescape';
|
||||
case 'optimizer';
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== true)
|
||||
{
|
||||
$message = '<error>Should be true</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, "\t" . $conf, $value, false, $message);
|
||||
break;
|
||||
case 'charset';
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== 'utf-8')
|
||||
{
|
||||
$message = '<comment>Not recognized</comment>';
|
||||
$this->alerts++;
|
||||
}
|
||||
|
||||
$this->printConf($output, "\t" . $conf, $value, false, $message);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, "\t" . $conf, $value, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function checkOrmService(OutputInterface $output)
|
||||
{
|
||||
$ormName = $this->configuration->getOrm();
|
||||
$configuration = $this->configuration->getService($ormName);
|
||||
|
||||
try
|
||||
{
|
||||
$service = Core\Service\Builder::create(\bootstrap::getCore(), $configuration);
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("\t--> Verify ORM engine <info>%s</info> : %s", $ormName, $work_message));
|
||||
|
||||
|
||||
|
||||
if (!$configuration->has('type'))
|
||||
{
|
||||
$output->writeln("\n<error>Configuration has no type</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
elseif ($configuration->get('type') == 'Orm\\Doctrine')
|
||||
{
|
||||
$required = array('debug', 'dbal', 'cache');
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\n<error>Your type is not managed</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach ($configuration->all() as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
case 'type':
|
||||
$message = $value == 'Orm\\Doctrine' ? '<info>OK</info>' : '<error>Not recognized</error>';
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'options':
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
$message = '<error>Should be array</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, 'array()', false, $message);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, $conf, 'unknown', false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($configuration->get('options') as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
case 'log':
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'cache':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
$message = '<error>Should be Array</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, 'array()', false, $message);
|
||||
|
||||
$required_caches = array('query', 'result', 'metadata');
|
||||
foreach ($value as $name => $cache_type)
|
||||
{
|
||||
$required_caches = array_diff($required_caches, array($name));
|
||||
|
||||
foreach ($cache_type as $key_cache => $value_cache)
|
||||
{
|
||||
switch ($key_cache)
|
||||
{
|
||||
case 'service':
|
||||
if ($this->probeCacheService($output, $value_cache))
|
||||
{
|
||||
$server = $name === 'result';
|
||||
if ($this->recommendedCacheService($output, $value_cache, $server))
|
||||
{
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errors++;
|
||||
$work_message = '<error>No cache required</error>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$verification = sprintf("\t--> Verify <info>%s</info> : %s", $name, $work_message);
|
||||
|
||||
|
||||
$this->printConf($output, "\t" . $key_cache, $value_cache, false, $verification);
|
||||
$this->verifyCacheOptions($output, $value_cache);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, "\t" . $key_cache, $value_cache, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
if (!isset($cache_type['service']))
|
||||
{
|
||||
$output->writeln('<error>Miss service for %s</error>', $cache_type);
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required_caches) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required caches %s</error>', implode(', ', $required_caches)));
|
||||
$this->errors++;
|
||||
}
|
||||
break;
|
||||
case 'debug':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== true)
|
||||
{
|
||||
$message = '<error>Should be true</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'dbal':
|
||||
$required = array_diff($required, array($conf));
|
||||
try
|
||||
{
|
||||
$connexion = $this->configuration->getConnexion($value);
|
||||
$this->verifyDatabaseConnexion($connexion);
|
||||
$message = '<info>OK</info>';
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$message = '<error>Failed</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, $conf, $value, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function verifyCacheOptions(OutputInterface $output, $ServiceName)
|
||||
{
|
||||
try
|
||||
{
|
||||
$conf = $this->configuration->getService($ServiceName);
|
||||
|
||||
$Service = Core\Service\Builder::create(
|
||||
\bootstrap::getCore(), $conf
|
||||
);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$required_options = array();
|
||||
|
||||
switch ($Service->getType())
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case 'memcache':
|
||||
$required_options = array('host', 'port');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($required_options)
|
||||
{
|
||||
foreach ($conf->get('options') as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
case 'host';
|
||||
$required_options = array_diff($required_options, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_scalar($value))
|
||||
{
|
||||
$message = '<error>Should be scalar</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, "\t\t" . $conf, $value, false, $message);
|
||||
break;
|
||||
case 'port';
|
||||
$required_options = array_diff($required_options, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!ctype_digit($value))
|
||||
{
|
||||
$message = '<comment>Not recognized</comment>';
|
||||
$this->alerts++;
|
||||
}
|
||||
|
||||
$this->printConf($output, "\t\t" . $conf, $value, false, $message);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, "\t\t" . $conf, $value, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required_options) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required_options)));
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
|
||||
protected function probeCacheService(OutputInterface $output, $ServiceName)
|
||||
{
|
||||
try
|
||||
{
|
||||
$originalConfiguration = $this->configuration->getService($ServiceName);
|
||||
|
||||
$Service = Core\Service\Builder::create(
|
||||
\bootstrap::getCore(), $originalConfiguration
|
||||
);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($Service->getDriver()->isServer())
|
||||
{
|
||||
switch ($Service->getType())
|
||||
{
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
case 'memcache':
|
||||
if (!@memcache_connect($Service->getHost(), $Service->getPort()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function recommendedCacheService(OutputInterface $output, $ServiceName, $server)
|
||||
{
|
||||
try
|
||||
{
|
||||
$originalConfiguration = $this->configuration->getService($ServiceName);
|
||||
|
||||
$Service = Core\Service\Builder::create(
|
||||
\bootstrap::getCore(), $originalConfiguration
|
||||
);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $Service->getType() === 'array';
|
||||
}
|
||||
|
||||
private function printConf($output, $scope, $value, $scopage = false, $message = '')
|
||||
{
|
||||
if (is_array($value))
|
||||
{
|
||||
foreach ($value as $key => $val)
|
||||
{
|
||||
if ($scopage)
|
||||
$key = $scope . ":" . $key;
|
||||
$this->printConf($output, $key, $val, $scopage, '');
|
||||
}
|
||||
}
|
||||
elseif (is_bool($value))
|
||||
{
|
||||
if ($value === false)
|
||||
{
|
||||
$value = 'false';
|
||||
}
|
||||
elseif ($value === true)
|
||||
{
|
||||
$value = 'true';
|
||||
}
|
||||
$output->writeln(sprintf("\t%s: %s %s", $scope, $value, $message));
|
||||
}
|
||||
elseif (!empty($value))
|
||||
{
|
||||
$output->writeln(sprintf("\t%s: %s %s", $scope, $value, $message));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
934
lib/classes/module/console/fileEnsureProductionSetting.class.php
Normal file
934
lib/classes/module/console/fileEnsureProductionSetting.class.php
Normal file
@@ -0,0 +1,934 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument,
|
||||
Symfony\Component\Console\Input\InputInterface,
|
||||
Symfony\Component\Console\Input\InputOption,
|
||||
Symfony\Component\Console\Output\OutputInterface,
|
||||
Symfony\Component\Console\Command\Command;
|
||||
use Alchemy\Phrasea\Core;
|
||||
use Symfony\Component\Yaml;
|
||||
|
||||
/**
|
||||
* @todo write tests
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class module_console_fileEnsureProductionSetting extends Command
|
||||
{
|
||||
|
||||
const ALERT = 1;
|
||||
const ERROR = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Alchemy\Phrasea\Core\Configuration
|
||||
*/
|
||||
protected $configuration;
|
||||
protected $testSuite = array(
|
||||
'checkPhraseanetScope'
|
||||
, 'checkDatabaseScope'
|
||||
, 'checkTeamplateEngineService'
|
||||
, 'checkOrmService'
|
||||
, 'checkCacheService'
|
||||
, 'checkOpcodeCacheService'
|
||||
);
|
||||
protected $errors = 0;
|
||||
protected $alerts = 0;
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Ensure production settings');
|
||||
|
||||
$this->addArgument('conf', InputArgument::OPTIONAL, 'The file to check', null);
|
||||
$this->addOption('strict', 's', InputOption::VALUE_NONE, 'Wheter to fail on alerts or not');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification();
|
||||
|
||||
$environnement = $input->getArgument('conf');
|
||||
|
||||
$this->configuration = \Alchemy\Phrasea\Core\Configuration::build($specifications, $environnement);
|
||||
|
||||
if (!$this->configuration->isInstalled())
|
||||
{
|
||||
$output->writeln(sprintf("\nPhraseanet is not installed\n"));
|
||||
}
|
||||
|
||||
$this->checkParse($output);
|
||||
$output->writeln(sprintf("Will Ensure Production Settings on <info>%s</info>", $this->configuration->getEnvironnement()));
|
||||
|
||||
$this->runTests($output);
|
||||
|
||||
$retval = $this->errors;
|
||||
if ($input->getOption('strict'))
|
||||
{
|
||||
$retval += $this->alerts;
|
||||
}
|
||||
|
||||
if ($retval > 0)
|
||||
{
|
||||
$output->writeln("\n<error>Some errors found in your conf</error>");
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\n<info>Your production settings are setted correctly ! Enjoy</info>");
|
||||
}
|
||||
$output->writeln('End');
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
private function runTests(OutputInterface $output)
|
||||
{
|
||||
foreach ($this->testSuite as $test)
|
||||
{
|
||||
$display = "";
|
||||
switch ($test)
|
||||
{
|
||||
case 'checkPhraseanetScope' :
|
||||
$display = "Phraseanet Configuration";
|
||||
break;
|
||||
case 'checkDatabaseScope' :
|
||||
$display = "Database";
|
||||
break;
|
||||
case 'checkTeamplateEngineService' :
|
||||
$display = "Template Engine";
|
||||
break;
|
||||
case 'checkOrmService' :
|
||||
$display = "ORM";
|
||||
break;
|
||||
case 'checkCacheService' :
|
||||
$display = "Cache";
|
||||
break;
|
||||
case 'checkOpcodeCacheService' :
|
||||
$display = "Opcode";
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('Unknown test');
|
||||
break;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("\n||| %s", mb_strtoupper($display)));
|
||||
|
||||
call_user_func(array($this, $test), $output);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkParse(OutputInterface $output)
|
||||
{
|
||||
|
||||
if (!$this->configuration->getConfigurations())
|
||||
{
|
||||
throw new \Exception("Unable to load configurations\n");
|
||||
}
|
||||
if (!$this->configuration->getConnexions())
|
||||
{
|
||||
throw new \Exception("Unable to load connexions\n");
|
||||
}
|
||||
if (!$this->configuration->getServices())
|
||||
{
|
||||
throw new \Exception("Unable to load services\n");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function checkCacheService(OutputInterface $output)
|
||||
{
|
||||
$cache = $this->configuration->getCache();
|
||||
|
||||
|
||||
if ($this->probeCacheService($output, $cache))
|
||||
{
|
||||
if ($this->recommendedCacheService($output, $cache, true))
|
||||
{
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<comment>Cache server recommended</comment>';
|
||||
$this->alerts++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$verification = sprintf("\t--> Verify <info>%s</info> : %s", 'MainCache', $work_message);
|
||||
|
||||
|
||||
$this->printConf($output, "\t" . 'service', $cache, false, $verification);
|
||||
$this->verifyCacheOptions($output, $cache);
|
||||
}
|
||||
|
||||
private function checkOpcodeCacheService(OutputInterface $output)
|
||||
{
|
||||
$cache = $this->configuration->getOpcodeCache();
|
||||
|
||||
|
||||
if ($this->probeCacheService($output, $cache))
|
||||
{
|
||||
if ($this->recommendedCacheService($output, $cache, false))
|
||||
{
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<comment>Opcode recommended</comment>';
|
||||
$this->alerts++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$verification = sprintf("\t--> Verify <info>%s</info> : %s", 'OpcodeCache', $work_message);
|
||||
|
||||
|
||||
$this->printConf($output, "\t" . 'service', $cache, false, $verification);
|
||||
$this->verifyCacheOptions($output, $cache);
|
||||
}
|
||||
|
||||
private function checkPhraseanetScope(OutputInterface $output)
|
||||
{
|
||||
$required = array('servername', 'maintenance', 'debug', 'display_errors', 'database');
|
||||
|
||||
$phraseanet = $this->configuration->getPhraseanet();
|
||||
|
||||
foreach ($phraseanet->all() as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, $conf, $value, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
case 'servername':
|
||||
$url = $value;
|
||||
$required = array_diff($required, array($conf));
|
||||
|
||||
$parseUrl = parse_url($url);
|
||||
|
||||
if (empty($url))
|
||||
{
|
||||
$message = "<error>should not be empty</error>";
|
||||
$this->errors++;
|
||||
}
|
||||
elseif ($url == 'http://sub.domain.tld/')
|
||||
{
|
||||
$this->alerts++;
|
||||
$message = "<comment>may be wrong</comment>";
|
||||
}
|
||||
elseif (!filter_var($url, FILTER_VALIDATE_URL))
|
||||
{
|
||||
$message = "<error>not valid</error>";
|
||||
$this->errors++;
|
||||
}
|
||||
elseif ($parseUrl["scheme"] !== "https")
|
||||
{
|
||||
$this->alerts++;
|
||||
$message = "<comment>should be https</comment>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = "<info>OK</info>";
|
||||
}
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'maintenance':
|
||||
case 'debug':
|
||||
case 'display_errors':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== false)
|
||||
{
|
||||
$message = '<error>Should be false</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'database':
|
||||
$required = array_diff($required, array($conf));
|
||||
try
|
||||
{
|
||||
$service = $this->configuration->getConnexion($value);
|
||||
if ($this->verifyDatabaseConnexion($service))
|
||||
{
|
||||
$message = '<info>OK</info>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = '<error>Connection not available</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$message = '<error>Unknown connection</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function checkDatabaseScope(OutputInterface $output)
|
||||
{
|
||||
$connexionName = $this->configuration->getPhraseanet()->get('database');
|
||||
$connexion = $this->configuration->getConnexion($connexionName);
|
||||
|
||||
try
|
||||
{
|
||||
if ($this->verifyDatabaseConnexion($connexion))
|
||||
{
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("\t--> Verify connection <info>%s</info> : %s", $connexionName, $work_message));
|
||||
|
||||
$required = array('driver');
|
||||
|
||||
if (!$connexion->has('driver'))
|
||||
{
|
||||
$output->writeln("\n<error>Connection has no driver</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
elseif ($connexion->get('driver') == 'pdo_mysql')
|
||||
{
|
||||
$required = array('driver', 'dbname', 'charset', 'password', 'user', 'port', 'host');
|
||||
}
|
||||
elseif ($connexion->get('driver') == 'pdo_sqlite')
|
||||
{
|
||||
$required = array('driver', 'path', 'charset');
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\n<error>Your driver is not managed</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
foreach ($connexion->all() as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, $conf, $value, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
case 'charset':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
if ($value !== 'UTF8')
|
||||
{
|
||||
$message = '<comment>Not recognized</comment>';
|
||||
$this->alerts++;
|
||||
}
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'path':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = is_writable(dirname($value)) ? '<info>OK</info>' : '<error>Not writeable</error>';
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'dbname':
|
||||
case 'user':
|
||||
case 'host':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_scalar($value))
|
||||
{
|
||||
$message = '<error>Should be scalar</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'port':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!ctype_digit($value))
|
||||
{
|
||||
$message = '<error>Should be ctype_digit</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'password':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_scalar($value))
|
||||
{
|
||||
$message = '<error>Should be scalar</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$value = '***********';
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'driver':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== 'pdo_mysql')
|
||||
{
|
||||
$message = '<error>MySQL recommended</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function verifyDatabaseConnexion(\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag $connexion)
|
||||
{
|
||||
try
|
||||
{
|
||||
$config = new \Doctrine\DBAL\Configuration();
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($connexion->all(), $config);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkTeamplateEngineService(OutputInterface $output)
|
||||
{
|
||||
$templateEngineName = $this->configuration->getTemplating();
|
||||
$configuration = $this->configuration->getService($templateEngineName);
|
||||
|
||||
try
|
||||
{
|
||||
Core\Service\Builder::create(\bootstrap::getCore(), $configuration);
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$work_message = '<error>Failed - could not load template engine !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("\t--> Verify Template engine <info>%s</info> : %s", $templateEngineName, $work_message));
|
||||
|
||||
if (!$configuration->has('type'))
|
||||
{
|
||||
$output->writeln("\n<error>Configuration has no type</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
elseif ($configuration->get('type') == 'TemplateEngine\\Twig')
|
||||
{
|
||||
$required = array('debug', 'charset', 'strict_variables', 'autoescape', 'optimizer');
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\n<error>Your type is not managed</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach ($configuration->all() as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
case 'type':
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if($value !== 'TemplateEngine\\Twig')
|
||||
{
|
||||
$message = '<error>Not recognized</error>';
|
||||
$this->alerts++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'options':
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
$message = '<error>Should be array</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, 'array()', false, $message);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, $conf, 'unknown', false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($configuration->get('options') as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
case 'debug';
|
||||
case 'strict_variables';
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== false)
|
||||
{
|
||||
$message = '<error>Should be false</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, "\t" . $conf, $value, false, $message);
|
||||
break;
|
||||
case 'autoescape';
|
||||
case 'optimizer';
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== true)
|
||||
{
|
||||
$message = '<error>Should be true</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, "\t" . $conf, $value, false, $message);
|
||||
break;
|
||||
case 'charset';
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== 'utf-8')
|
||||
{
|
||||
$message = '<comment>Not recognized</comment>';
|
||||
$this->alerts++;
|
||||
}
|
||||
|
||||
$this->printConf($output, "\t" . $conf, $value, false, $message);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, "\t" . $conf, $value, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function checkOrmService(OutputInterface $output)
|
||||
{
|
||||
$ormName = $this->configuration->getOrm();
|
||||
$configuration = $this->configuration->getService($ormName);
|
||||
|
||||
try
|
||||
{
|
||||
$service = Core\Service\Builder::create(\bootstrap::getCore(), $configuration);
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("\t--> Verify ORM engine <info>%s</info> : %s", $ormName, $work_message));
|
||||
|
||||
|
||||
|
||||
if (!$configuration->has('type'))
|
||||
{
|
||||
$output->writeln("\n<error>Configuration has no type</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
elseif ($configuration->get('type') == 'Orm\\Doctrine')
|
||||
{
|
||||
$required = array('debug', 'dbal', 'cache');
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\n<error>Your type is not managed</error>");
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach ($configuration->all() as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
case 'type':
|
||||
$message = $value == 'Orm\\Doctrine' ? '<info>OK</info>' : '<error>Not recognized</error>';
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'options':
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
$message = '<error>Should be array</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, 'array()', false, $message);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, $conf, 'unknown', false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($configuration->get('options') as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
case 'log':
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== false)
|
||||
{
|
||||
$message = '<error>Should be deactivated</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'cache':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
$message = '<error>Should be Array</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, 'array()', false, $message);
|
||||
|
||||
$required_caches = array('query', 'result', 'metadata');
|
||||
foreach ($value as $name => $cache_type)
|
||||
{
|
||||
$required_caches = array_diff($required_caches, array($name));
|
||||
|
||||
foreach ($cache_type as $key_cache => $value_cache)
|
||||
{
|
||||
switch ($key_cache)
|
||||
{
|
||||
case 'service':
|
||||
if ($this->probeCacheService($output, $value_cache))
|
||||
{
|
||||
$server = $name === 'result';
|
||||
if ($this->recommendedCacheService($output, $value_cache, $server))
|
||||
{
|
||||
$work_message = '<info>Works !</info>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->alerts++;
|
||||
if ($server)
|
||||
{
|
||||
$work_message = '<comment>Cache server recommended</comment>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<comment>Opcode cache recommended</comment>';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$work_message = '<error>Failed - could not connect !</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$verification = sprintf("\t--> Verify <info>%s</info> : %s", $name, $work_message);
|
||||
|
||||
|
||||
$this->printConf($output, "\t" . $key_cache, $value_cache, false, $verification);
|
||||
$this->verifyCacheOptions($output, $value_cache);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, "\t" . $key_cache, $value_cache, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
if (!isset($cache_type['service']))
|
||||
{
|
||||
$output->writeln('<error>Miss service for %s</error>', $cache_type);
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required_caches) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required caches %s</error>', implode(', ', $required_caches)));
|
||||
$this->errors++;
|
||||
}
|
||||
break;
|
||||
case 'debug':
|
||||
$required = array_diff($required, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if ($value !== false)
|
||||
{
|
||||
$message = '<error>Should be false</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
case 'dbal':
|
||||
$required = array_diff($required, array($conf));
|
||||
try
|
||||
{
|
||||
$connexion = $this->configuration->getConnexion($value);
|
||||
$this->verifyDatabaseConnexion($connexion);
|
||||
$message = '<info>OK</info>';
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$message = '<error>Failed</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
$this->printConf($output, $conf, $value, false, $message);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, $conf, $value, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function verifyCacheOptions(OutputInterface $output, $ServiceName)
|
||||
{
|
||||
try
|
||||
{
|
||||
$conf = $this->configuration->getService($ServiceName);
|
||||
|
||||
$Service = Core\Service\Builder::create(
|
||||
\bootstrap::getCore(), $conf
|
||||
);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$required_options = array();
|
||||
|
||||
switch ($Service->getType())
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case 'memcache':
|
||||
$required_options = array('host', 'port');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($required_options)
|
||||
{
|
||||
foreach ($conf->get('options') as $conf => $value)
|
||||
{
|
||||
switch ($conf)
|
||||
{
|
||||
case 'host';
|
||||
$required_options = array_diff($required_options, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!is_scalar($value))
|
||||
{
|
||||
$message = '<error>Should be scalar</error>';
|
||||
$this->errors++;
|
||||
}
|
||||
|
||||
$this->printConf($output, "\t\t" . $conf, $value, false, $message);
|
||||
break;
|
||||
case 'port';
|
||||
$required_options = array_diff($required_options, array($conf));
|
||||
$message = '<info>OK</info>';
|
||||
|
||||
if (!ctype_digit($value))
|
||||
{
|
||||
$message = '<comment>Not recognized</comment>';
|
||||
$this->alerts++;
|
||||
}
|
||||
|
||||
$this->printConf($output, "\t\t" . $conf, $value, false, $message);
|
||||
break;
|
||||
default:
|
||||
$this->alerts++;
|
||||
$this->printConf($output, "\t\t" . $conf, $value, false, '<comment>Not recognized</comment>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($required_options) > 0)
|
||||
{
|
||||
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required_options)));
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
|
||||
protected function probeCacheService(OutputInterface $output, $ServiceName)
|
||||
{
|
||||
try
|
||||
{
|
||||
$originalConfiguration = $this->configuration->getService($ServiceName);
|
||||
|
||||
$Service = Core\Service\Builder::create(
|
||||
\bootstrap::getCore(), $originalConfiguration
|
||||
);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($Service->getDriver()->isServer())
|
||||
{
|
||||
switch ($Service->getType())
|
||||
{
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
case 'memcache':
|
||||
if (!@memcache_connect($Service->getHost(), $Service->getPort()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function recommendedCacheService(OutputInterface $output, $ServiceName, $server)
|
||||
{
|
||||
try
|
||||
{
|
||||
$originalConfiguration = $this->configuration->getService($ServiceName);
|
||||
|
||||
$Service = Core\Service\Builder::create(
|
||||
\bootstrap::getCore(), $originalConfiguration
|
||||
);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($Service->getType() === 'array')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $server === $Service->getDriver()->isServer();
|
||||
}
|
||||
|
||||
private function printConf($output, $scope, $value, $scopage = false, $message = '')
|
||||
{
|
||||
if (is_array($value))
|
||||
{
|
||||
foreach ($value as $key => $val)
|
||||
{
|
||||
if ($scopage)
|
||||
$key = $scope . ":" . $key;
|
||||
$this->printConf($output, $key, $val, $scopage, '');
|
||||
}
|
||||
}
|
||||
elseif (is_bool($value))
|
||||
{
|
||||
if ($value === false)
|
||||
{
|
||||
$value = 'false';
|
||||
}
|
||||
elseif ($value === true)
|
||||
{
|
||||
$value = 'true';
|
||||
}
|
||||
$output->writeln(sprintf("\t%s: %s %s", $scope, $value, $message));
|
||||
}
|
||||
elseif (!empty($value))
|
||||
{
|
||||
$output->writeln(sprintf("\t%s: %s %s", $scope, $value, $message));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
@@ -54,17 +55,27 @@ class module_console_schedulerStart extends Command
|
||||
|
||||
public function execute(InputInterface $zinput, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$scheduler = new task_Scheduler();
|
||||
$scheduler->run($zinput, $output); //, !$input->getOption('nolog'), !$input->getOption('notasklog'));
|
||||
|
||||
return;
|
||||
try
|
||||
{
|
||||
$scheduler = new task_Scheduler();
|
||||
$scheduler->run($output, true);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_schedulerState extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
@@ -35,26 +36,39 @@ class module_console_schedulerState extends Command
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
try
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
$state = $task_manager->get_scheduler_state();
|
||||
if ($state['schedstatus'] == 'started')
|
||||
{
|
||||
$output->writeln(sprintf(
|
||||
'Scheduler is %s on pid %d'
|
||||
, $state['schedstatus']
|
||||
, $state['schedpid']
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln(sprintf('Scheduler is %s', $state['schedstatus']));
|
||||
}
|
||||
|
||||
$state = $task_manager->get_scheduler_state();
|
||||
|
||||
if ($state['schedstatus'] == 'started')
|
||||
$output->writeln(sprintf(
|
||||
'Scheduler is %s on pid %d'
|
||||
, $state['schedstatus']
|
||||
, $state['schedpid']
|
||||
));
|
||||
else
|
||||
$output->writeln(sprintf('Scheduler is %s', $state['schedstatus']));
|
||||
return 0;
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -33,19 +33,30 @@ class module_console_schedulerStop extends Command
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
try
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
$task_manager->set_sched_status(task_manager::STATUS_SCHED_TOSTOP);
|
||||
|
||||
$task_manager->set_sched_status(task_manager::STATUS_SCHED_TOSTOP);
|
||||
return 0;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
162
lib/classes/module/console/sphinxGenerateSuggestion.class.php
Normal file
162
lib/classes/module/console/sphinxGenerateSuggestion.class.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_sphinxGenerateSuggestion extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Generate suggestions for Sphinx Search Engine');
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
define('FREQ_THRESHOLD', 10);
|
||||
define('SUGGEST_DEBUG', 0);
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
$params = phrasea::sbas_params();
|
||||
|
||||
foreach ($params as $sbas_id => $p)
|
||||
{
|
||||
$index = crc32(
|
||||
str_replace(
|
||||
array('.', '%')
|
||||
, '_'
|
||||
, sprintf('%s_%s_%s_%s', $p['host'], $p['port'], $p['user'], $p['dbname'])
|
||||
)
|
||||
);
|
||||
|
||||
$tmp_file = $registry->get('GV_RootPath') . 'tmp/dict' . $index . '.txt';
|
||||
|
||||
$databox = databox::get_instance($sbas_id);
|
||||
|
||||
$output->writeln("process Databox " . $databox->get_viewname() . " / $index\n");
|
||||
|
||||
if(!is_executable("/usr/local/bin/indexer"))
|
||||
{
|
||||
$output->writeln("<error>'/usr/local/bin/indexer' is not executable</error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!file_exists($tmp_file))
|
||||
{
|
||||
$output->writeln("<error> file '".$tmp_file."' does not exist</error>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$cmd = '/usr/local/bin/indexer metadatas' . $index . ' --buildstops ' . $tmp_file . ' 1000000 --buildfreqs';
|
||||
exec($cmd);
|
||||
|
||||
try
|
||||
{
|
||||
$connbas = connection::getPDOConnection($sbas_id);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$sql = 'TRUNCATE suggest';
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = $this->BuildDictionarySQL($output, file_get_contents($tmp_file));
|
||||
|
||||
if (trim($sql) !== '')
|
||||
{
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
unlink($tmp_file);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function BuildTrigrams($keyword)
|
||||
{
|
||||
$t = "__" . $keyword . "__";
|
||||
|
||||
$trigrams = "";
|
||||
for ($i = 0; $i < strlen($t) - 2; $i++)
|
||||
$trigrams .= substr($t, $i, 3) . " ";
|
||||
|
||||
return $trigrams;
|
||||
}
|
||||
|
||||
protected function BuildDictionarySQL(OutputInterface $output, $in)
|
||||
{
|
||||
$out = '';
|
||||
|
||||
$n = 0;
|
||||
$lines = explode("\n", $in);
|
||||
foreach ($lines as $line)
|
||||
{
|
||||
if (trim($line) === '')
|
||||
continue;
|
||||
list ( $keyword, $freq ) = explode(" ", trim($line));
|
||||
|
||||
if ($freq < FREQ_THRESHOLD || strstr($keyword, "_") !== false || strstr($keyword, "'") !== false)
|
||||
continue;
|
||||
|
||||
if (ctype_digit($keyword))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (mb_strlen($keyword) < 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$trigrams = $this->BuildTrigrams($keyword);
|
||||
|
||||
if ($n++)
|
||||
$out .= ",\n";
|
||||
$out .= "( $n, '$keyword', '$trigrams', $freq )";
|
||||
}
|
||||
|
||||
if (trim($out) !== '')
|
||||
{
|
||||
$out = "INSERT INTO suggest VALUES " . $out . ";";
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("Generated <info>%d</info> suggestions", $n));
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
}
|
@@ -31,7 +31,7 @@ class module_console_systemBackupDB extends Command
|
||||
|
||||
$dir = sprintf(
|
||||
'%s/config/'
|
||||
, dirname(dirname(dirname(dirname(dirname(__FILE__)))))
|
||||
, dirname(dirname(dirname(dirname(__DIR__))))
|
||||
);
|
||||
|
||||
$this->setDescription('Backup Phraseanet Databases');
|
||||
@@ -45,23 +45,27 @@ class module_console_systemBackupDB extends Command
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Argument must be an Id.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$output->write('Phraseanet is going to be backup...', true);
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$this->dump_base($appbox, $input, $output);
|
||||
$ok = true;
|
||||
|
||||
$ok = $this->dump_base($appbox, $input, $output) && $ok;
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
{
|
||||
$this->dump_base($databox, $input, $output);
|
||||
$ok = $this->dump_base($databox, $input, $output) && $ok;
|
||||
}
|
||||
|
||||
return;
|
||||
return (int) !$ok;
|
||||
}
|
||||
|
||||
protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
|
||||
@@ -91,11 +95,19 @@ class module_console_systemBackupDB extends Command
|
||||
system($command);
|
||||
|
||||
if (file_exists($filename) && filesize($filename) > 0)
|
||||
{
|
||||
$output->writeln('OK');
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln('<error>Failed</error>');
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -44,10 +44,10 @@ class module_console_systemClearCache extends Command
|
||||
->exclude('.git')
|
||||
->exclude('.svn')
|
||||
->in(array(
|
||||
dirname(__FILE__) . '/../../../../tmp/cache_minify/'
|
||||
, dirname(__FILE__) . '/../../../../tmp/cache_twig/'
|
||||
))
|
||||
;
|
||||
__DIR__ . '/../../../../tmp/cache_minify/'
|
||||
, __DIR__ . '/../../../../tmp/cache_twig/'
|
||||
));
|
||||
|
||||
$count = 1;
|
||||
foreach ($finder as $file)
|
||||
{
|
||||
@@ -59,12 +59,12 @@ class module_console_systemClearCache extends Command
|
||||
$finder
|
||||
->directories()
|
||||
->in(array(
|
||||
dirname(__FILE__) . '/../../../../tmp/cache_minify'
|
||||
, dirname(__FILE__) . '/../../../../tmp/cache_twig'
|
||||
__DIR__ . '/../../../../tmp/cache_minify'
|
||||
, __DIR__ . '/../../../../tmp/cache_twig'
|
||||
))
|
||||
->exclude('.git')
|
||||
->exclude('.svn')
|
||||
;
|
||||
->exclude('.svn');
|
||||
|
||||
foreach ($finder as $file)
|
||||
{
|
||||
$dirs[$file->getPathname()] = $file->getPathname();
|
||||
@@ -83,17 +83,13 @@ class module_console_systemClearCache extends Command
|
||||
|
||||
if(setup::is_installed())
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$cache = cache_adapter::get_instance($registry);
|
||||
if($cache->ping())
|
||||
{
|
||||
$cache->flush();
|
||||
}
|
||||
$Core = \bootstrap::getCore();
|
||||
$Core['CacheService']->flushAll();
|
||||
}
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -42,15 +42,17 @@ class module_console_systemConfigCheck extends Command
|
||||
$output->writeln('<error>YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET</error>');
|
||||
$output->writeln('Canceled');
|
||||
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
$ok = true;
|
||||
|
||||
if (setup::is_installed())
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$output->writeln(_('*** CHECK BINARY CONFIGURATION ***'));
|
||||
$this->processConstraints(setup::check_binaries($registry), $output);
|
||||
$ok = $this->processConstraints(setup::check_binaries($registry), $output) && $ok;
|
||||
$output->writeln("");
|
||||
}
|
||||
else
|
||||
@@ -58,51 +60,67 @@ class module_console_systemConfigCheck extends Command
|
||||
$registry = new Setup_Registry();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$output->writeln(_('*** FILESYSTEM CONFIGURATION ***'));
|
||||
$this->processConstraints(setup::check_writability($registry), $output);
|
||||
$ok = $this->processConstraints(setup::check_writability($registry), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK CACHE OPCODE ***'));
|
||||
$this->processConstraints(setup::check_cache_opcode(), $output);
|
||||
$ok = $this->processConstraints(setup::check_cache_opcode(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK CACHE SERVER ***'));
|
||||
$this->processConstraints(setup::check_cache_server(), $output);
|
||||
$ok = $this->processConstraints(setup::check_cache_server(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHP CONFIGURATION ***'));
|
||||
$this->processConstraints(setup::check_php_configuration(), $output);
|
||||
$ok = $this->processConstraints(setup::check_php_configuration(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHP EXTENSIONS ***'));
|
||||
$this->processConstraints(setup::check_php_extension(), $output);
|
||||
$ok = $this->processConstraints(setup::check_php_extension(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHRASEA ***'));
|
||||
$this->processConstraints(setup::check_phrasea(), $output);
|
||||
$ok = $this->processConstraints(setup::check_phrasea(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK SYSTEM LOCALES ***'));
|
||||
$this->processConstraints(setup::check_system_locales(), $output);
|
||||
$ok = $this->processConstraints(setup::check_system_locales(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return;
|
||||
return (int)!$ok;
|
||||
}
|
||||
|
||||
protected function processConstraints(Setup_ConstraintsIterator $constraints, OutputInterface &$output)
|
||||
{
|
||||
$hasError = false;
|
||||
foreach ($constraints as $constraint)
|
||||
{
|
||||
$this->processConstraint($constraint, $output);
|
||||
if (!$hasError && !$this->processConstraint($constraint, $output))
|
||||
{
|
||||
$hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
return !$hasError;
|
||||
}
|
||||
|
||||
protected function processConstraint(Setup_Constraint $constraint, OutputInterface &$output)
|
||||
{
|
||||
$ok = true;
|
||||
if ($constraint->is_ok())
|
||||
{
|
||||
$output->writeln("\t\t<info>" . $constraint->get_message() . '</info>');
|
||||
}
|
||||
elseif ($constraint->is_blocker())
|
||||
{
|
||||
$output->writeln("\t!!!\t<error>" . $constraint->get_message() . '</error>');
|
||||
$ok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\t/!\\\t<comment>" . $constraint->get_message() . '</comment>');
|
||||
}
|
||||
|
||||
return;
|
||||
return $ok;
|
||||
}
|
||||
|
||||
}
|
||||
|
311
lib/classes/module/console/systemExport.class.php
Normal file
311
lib/classes/module/console/systemExport.class.php
Normal file
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package KonsoleKomander
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_systemExport extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->setDescription('Export all phraseanet records to a directory');
|
||||
|
||||
/**
|
||||
* To implement
|
||||
*/
|
||||
// $this->addOption('useoriginalname', 'o', InputOption::VALUE_OPTIONAL
|
||||
// , 'Use original name for dest files', false);
|
||||
|
||||
/**
|
||||
* To implement
|
||||
*/
|
||||
// $this->addOption('excludefield', 'f', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
// , 'Exclude field from XML', array());
|
||||
|
||||
/**
|
||||
* To implement
|
||||
*/
|
||||
// $this->addOption('excludestatus', '', InputOption::VALUE_OPTIONAL
|
||||
// , 'Exclude Status', false);
|
||||
|
||||
$this->addOption('docperdir', 'd', InputOption::VALUE_OPTIONAL
|
||||
, 'Maximum number of files per dir', 100);
|
||||
|
||||
$this->addOption('caption', 'c', InputOption::VALUE_OPTIONAL
|
||||
, 'Export Caption (XML)', false);
|
||||
|
||||
$this->addOption('limit', 'l', InputOption::VALUE_OPTIONAL
|
||||
, 'Limit files quantity (for test purposes)', false);
|
||||
|
||||
$this->addOption('base_id', 'b', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
, 'Restrict on base_ids', array());
|
||||
|
||||
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
|
||||
, 'Restrict on sbas_ids', array());
|
||||
|
||||
$this->addArgument('directory', InputOption::VALUE_REQUIRED
|
||||
, 'The directory where to export');
|
||||
|
||||
$this->addOption('sanitize', '', InputOption::VALUE_REQUIRED
|
||||
, 'Sanitize filenames. Set to 0 to disable', true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$docPerDir = max(1, (int) $input->getOption('docperdir'));
|
||||
|
||||
/**
|
||||
*
|
||||
* To implement
|
||||
*
|
||||
$useOriginalName = !!$input->getOption('useoriginalname');
|
||||
$excludeFields = $input->getOption('excludefield');
|
||||
$exportStatus = !$input->getOption('excludestatus');
|
||||
*
|
||||
*/
|
||||
|
||||
$Caption = $input->getOption('caption');
|
||||
|
||||
$limit = ctype_digit($input->getOption('limit')) ? max(0, (int) $input->getOption('limit')) : false;
|
||||
|
||||
$restrictBaseIds = $input->getOption('base_id');
|
||||
|
||||
$restrictSbasIds = $input->getOption('sbas_id');
|
||||
|
||||
$sanitize = $input->getOption('sanitize');
|
||||
|
||||
|
||||
$export_directory = $input->getArgument('directory');
|
||||
|
||||
if (!$export_directory)
|
||||
{
|
||||
throw new Exception('Missing directory argument');
|
||||
}
|
||||
|
||||
$export_directory = realpath(substr($export_directory, 0, 1) === '/' ? $export_directory : getcwd() . '/' . $export_directory . '/');
|
||||
|
||||
if (!$export_directory)
|
||||
{
|
||||
throw new Exception('Export directory does not exists or is not accessible');
|
||||
}
|
||||
|
||||
if (!is_writable($export_directory))
|
||||
{
|
||||
throw new Exception('Export directory is not writable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize
|
||||
*/
|
||||
foreach ($restrictBaseIds as $key => $base_id)
|
||||
{
|
||||
$restrictBaseIds[$key] = (int) $base_id;
|
||||
}
|
||||
foreach ($restrictSbasIds as $key => $sbas_id)
|
||||
{
|
||||
$restrictSbasIds[$key] = (int) $sbas_id;
|
||||
}
|
||||
|
||||
|
||||
if (count($restrictSbasIds) > 0)
|
||||
{
|
||||
$output->writeln("Export datas from selected sbas_ids");
|
||||
}
|
||||
elseif (count($restrictBaseIds) > 0)
|
||||
{
|
||||
$output->writeln("Export datas from selected base_ids");
|
||||
}
|
||||
|
||||
$appbox = \appbox::get_instance();
|
||||
|
||||
$total = $errors = 0;
|
||||
|
||||
$unicode = new \unicode();
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
{
|
||||
$output->writeln(sprintf("Processing <info>%s</info>", $databox->get_viewname()));
|
||||
|
||||
if (count($restrictSbasIds) > 0 && !in_array($databox->get_sbas_id(), $restrictSbasIds))
|
||||
{
|
||||
$output->writeln(sprintf("Databox not selected, bypassing ..."));
|
||||
continue;
|
||||
}
|
||||
|
||||
$go = true;
|
||||
$coll_ids = array();
|
||||
|
||||
if (count($restrictBaseIds) > 0)
|
||||
{
|
||||
$go = false;
|
||||
foreach ($databox->get_collections() as $collection)
|
||||
{
|
||||
if (in_array($collection->get_base_id(), $restrictBaseIds))
|
||||
{
|
||||
|
||||
$go = true;
|
||||
$coll_ids[] = $collection->get_coll_id();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$go)
|
||||
{
|
||||
$output->writeln(sprintf("Collections not selected, bypassing ..."));
|
||||
continue;
|
||||
}
|
||||
|
||||
$local_export = $export_directory
|
||||
. '/' . $unicode->remove_nonazAZ09($databox->get_viewname(), true, true)
|
||||
. '/';
|
||||
|
||||
system_file::mkdir($local_export);
|
||||
|
||||
$sql = 'SELECT record_id FROM record WHERE parent_record_id = 0 ';
|
||||
|
||||
if (count($coll_ids) > 0)
|
||||
{
|
||||
$sql .= ' AND coll_id IN (' . implode(', ', $coll_ids) . ') ';
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY record_id ASC ';
|
||||
|
||||
if ($limit)
|
||||
{
|
||||
$sql .= ' LIMIT 0, ' . $limit;
|
||||
}
|
||||
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
|
||||
$done = 0;
|
||||
$current_total = count($rs);
|
||||
$total += $current_total;
|
||||
$l = strlen((string) $current_total) + 1;
|
||||
|
||||
$dir_format = 'datas%' . strlen((string) ceil($current_total / $docPerDir)) . 'd';
|
||||
|
||||
$dir_increment = 0;
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$record = $databox->get_record($row['record_id']);
|
||||
if (($done % $docPerDir) === 0)
|
||||
{
|
||||
$dir_increment++;
|
||||
$in_dir_files = array();
|
||||
$current_dir = $local_export . sprintf($dir_format, $dir_increment) . '/';
|
||||
system_file::mkdir($current_dir);
|
||||
}
|
||||
|
||||
if ($sanitize)
|
||||
{
|
||||
$filename = $unicode->remove_nonazAZ09($record->get_original_name(), true, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$filename = $record->get_original_name();
|
||||
}
|
||||
|
||||
$this->generateDefinitiveFilename($in_dir_files, $filename);
|
||||
|
||||
$output_file = $current_dir . $filename;
|
||||
|
||||
if (!$this->processRecords($record, $output_file, $Caption))
|
||||
{
|
||||
$errors++;
|
||||
}
|
||||
|
||||
$done++;
|
||||
|
||||
$output->write(sprintf("\r#%" . $l . "d record remaining", $current_total - $done));
|
||||
}
|
||||
$output->writeln(" | " . $current_total . " records done\n");
|
||||
}
|
||||
|
||||
$output->writeln("$total records done, $errors errors occured");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function generateDefinitiveFilename(array &$existing, &$filename)
|
||||
{
|
||||
$definitive_filename = $filename;
|
||||
$suffix = 2;
|
||||
while (array_key_exists($definitive_filename, $existing))
|
||||
{
|
||||
$pathinfo = pathinfo($filename);
|
||||
|
||||
$definitive_filename = $pathinfo['filename'] . '_' . $suffix .
|
||||
(isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : '');
|
||||
$suffix++;
|
||||
}
|
||||
|
||||
$existing[$filename] = $filename;
|
||||
$filename = $definitive_filename;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function processRecords(\record_adapter $record, $outfile, $caption)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
$file = new system_file($record->get_subdef('document')->get_pathfile());
|
||||
}
|
||||
catch (\Exception_Media_SubdefNotFound $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
copy($file->getPathname(), $outfile);
|
||||
|
||||
$dest_file = new system_file($outfile);
|
||||
|
||||
touch(
|
||||
$dest_file->getPathname()
|
||||
, $record->get_creation_date()->format('U')
|
||||
, $record->get_modification_date()->format('U')
|
||||
);
|
||||
|
||||
switch (strtolower($caption))
|
||||
{
|
||||
case 'xml':
|
||||
$pathinfo = pathinfo($dest_file->getPathname());
|
||||
$xml_file = dirname($outfile) . '/' . $pathinfo['filename'] . '.xml';
|
||||
file_put_contents($xml_file, $record->get_xml());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@@ -43,7 +43,7 @@ class module_console_systemMailCheck extends Command
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$output->writeln("Processing...");
|
||||
|
||||
@@ -65,7 +65,7 @@ class module_console_systemMailCheck extends Command
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function manage_group($email, $users, $output, $appbox)
|
||||
|
@@ -36,16 +36,16 @@ class module_console_systemTemplateGenerator extends Command
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
require_once dirname(__FILE__) . '/../../../../lib/vendor/Twig/lib/Twig/Autoloader.php';
|
||||
require_once dirname(__FILE__) . '/../../../../lib/vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php';
|
||||
require_once __DIR__ . '/../../../../lib/vendor/Twig/lib/Twig/Autoloader.php';
|
||||
require_once __DIR__ . '/../../../../lib/vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php';
|
||||
|
||||
|
||||
Twig_Autoloader::register();
|
||||
Twig_Extensions_Autoloader::register();
|
||||
|
||||
|
||||
$tplDir = dirname(__FILE__) . '/../../../../templates/';
|
||||
$tmpDir = dirname(__FILE__) . '/../../../../tmp/cache_twig/';
|
||||
$tplDir = __DIR__ . '/../../../../templates/';
|
||||
$tmpDir = __DIR__ . '/../../../../tmp/cache_twig/';
|
||||
$loader = new Twig_Loader_Filesystem($tplDir);
|
||||
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
@@ -54,7 +54,9 @@ class module_console_systemTemplateGenerator extends Command
|
||||
));
|
||||
$twig->addExtension(new Twig_Extensions_Extension_I18n());
|
||||
|
||||
|
||||
/**
|
||||
* @todo clean all duplicate filters
|
||||
*/
|
||||
$twig->addFilter('serialize', new Twig_Filter_Function('serialize'));
|
||||
$twig->addFilter('sbas_names', new Twig_Filter_Function('phrasea::sbas_names'));
|
||||
$twig->addFilter('sbas_name', new Twig_Filter_Function('phrasea::sbas_names'));
|
||||
@@ -78,9 +80,11 @@ class module_console_systemTemplateGenerator extends Command
|
||||
$twig->addFilter('key_exists', new Twig_Filter_Function('array_key_exists'));
|
||||
$twig->addFilter('array_keys', new Twig_Filter_Function('array_keys'));
|
||||
$twig->addFilter('round', new Twig_Filter_Function('round'));
|
||||
$twig->addFilter('get_class', new Twig_Filter_Function('get_class'));
|
||||
$twig->addFilter('formatdate', new Twig_Filter_Function('phraseadate::getDate'));
|
||||
$twig->addFilter('getPrettyDate', new Twig_Filter_Function('phraseadate::getPrettyString'));
|
||||
$twig->addFilter('prettyDate', new Twig_Filter_Function('phraseadate::getPrettyString'));
|
||||
$twig->addFilter('prettyString', new Twig_Filter_Function('phraseadate::getPrettyString'));
|
||||
$twig->addFilter('formatoctet', new Twig_Filter_Function('p4string::format_octet'));
|
||||
$twig->addFilter('getDate', new Twig_Filter_Function('phraseadate::getDate'));
|
||||
$twig->addFilter('geoname_name_from_id', new Twig_Filter_Function('geonames::name_from_id'));
|
||||
@@ -118,7 +122,7 @@ class module_console_systemTemplateGenerator extends Command
|
||||
|
||||
$output->writeln("");
|
||||
|
||||
return;
|
||||
return $n_error;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
@@ -36,47 +37,41 @@ class module_console_systemUpgrade extends Command
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$Core = \bootstrap::getCore();
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
|
||||
if (file_exists(dirname(__FILE__) . "/../../../../config/connexion.inc")
|
||||
&& !file_exists(dirname(__FILE__) . "/../../../../config/config.inc")
|
||||
&& file_exists(dirname(__FILE__) . "/../../../../config/_GV.php"))
|
||||
$output->writeln('This version of Phraseanet requires a config/config.yml, config/connexion.yml, config/service.yml');
|
||||
$output->writeln('Would you like it to be created based on your settings ?');
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
do
|
||||
{
|
||||
|
||||
$output->writeln('This version of Phraseanet requires a config/config.inc');
|
||||
$output->writeln('Would you like it to be created based on your settings ?');
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
do
|
||||
{
|
||||
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Create automatically') . ' (Y/n)</question>', 'y'));
|
||||
}
|
||||
while (!in_array($continue, array('y', 'n')));
|
||||
|
||||
if ($continue == 'y')
|
||||
{
|
||||
require __DIR__ . "/../../../../config/_GV.php";
|
||||
|
||||
$datas = '<?php'."\n"
|
||||
.'$servername = "'.GV_ServerName.'";'."\n"
|
||||
.'$maintenance=false;'."\n"
|
||||
.'$debug=false;'."\n"
|
||||
.'$debug=true;'."\n"
|
||||
.'';
|
||||
|
||||
file_put_contents(__DIR__ . "/../../../../config/config.inc", $datas);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
|
||||
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Create automatically') . ' (Y/n)</question>', 'y'));
|
||||
}
|
||||
while (!in_array($continue, array('y', 'n')));
|
||||
|
||||
if ($continue == 'y')
|
||||
{
|
||||
try
|
||||
{
|
||||
$connexionInc = new \SplFileObject(__DIR__ . '/../../../../config/connexion.inc');
|
||||
$configInc = new \SplFileObject(__DIR__ . '/../../../../config/config.inc');
|
||||
|
||||
$Core->getConfiguration()->upgradeFromOldConf($configInc, $connexionInc);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
}
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$output->write('Phraseanet is going to be upgraded', true);
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
@@ -92,8 +87,9 @@ class module_console_systemUpgrade extends Command
|
||||
{
|
||||
try
|
||||
{
|
||||
$Core = \bootstrap::getCore();
|
||||
$output->write('<info>Upgrading...</info>', true);
|
||||
$appbox = appbox::get_instance();
|
||||
$appbox = appbox::get_instance($Core);
|
||||
|
||||
if (count(User_Adapter::get_wrong_email_users($appbox)) > 0)
|
||||
{
|
||||
@@ -101,10 +97,11 @@ class module_console_systemUpgrade extends Command
|
||||
}
|
||||
|
||||
$upgrader = new Setup_Upgrade($appbox);
|
||||
$advices = $appbox->forceUpgrade($upgrader);
|
||||
$advices = $appbox->forceUpgrade($upgrader);
|
||||
}
|
||||
catch (Exception $e)
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
$output->writeln(sprintf('<error>An error occured while upgrading : %s </error>', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
@@ -37,34 +37,45 @@ class module_console_tasklist extends Command
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
|
||||
if(count($tasks) === 0)
|
||||
$output->writeln ('No tasks on your install !');
|
||||
|
||||
foreach($tasks as $task)
|
||||
try
|
||||
{
|
||||
$this->print_task($task, $output);
|
||||
}
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
|
||||
return $this;
|
||||
if (count($tasks) === 0)
|
||||
{
|
||||
$output->writeln('No tasks on your install !');
|
||||
}
|
||||
|
||||
foreach ($tasks as $task)
|
||||
{
|
||||
$this->print_task($task, $output);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function print_task(task_abstract $task, OutputInterface &$output)
|
||||
{
|
||||
$message = $task->get_task_id()."\t".($task->get_status() )."\t".$task->get_title();
|
||||
$message = $task->get_task_id() . "\t" . ($task->get_status() ) . "\t" . $task->get_title();
|
||||
$output->writeln($message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -67,12 +67,14 @@ class module_console_taskrun extends Command
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(!setup::is_installed())
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
$task_id = (int) $input->getArgument('task_id');
|
||||
|
||||
@@ -104,8 +106,10 @@ class module_console_taskrun extends Command
|
||||
|
||||
$this->task->log(sprintf("%s [%d] taskrun : returned from 'run()', get_status()=%s \n", __FILE__, __LINE__, $this->task->get_status()));
|
||||
|
||||
return $this;
|
||||
}
|
||||
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
|
||||
{
|
||||
$runner = task_abstract::RUNNER_MANUAL;
|
||||
}
|
||||
|
||||
public function tick_handler()
|
||||
{
|
||||
@@ -131,4 +135,4 @@ $this->task->log(sprintf("%s [%d] taskrun : returned from 'run()', get_status()=
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user