This commit is contained in:
Romain Neutron
2012-04-26 00:55:53 +02:00
parent edbfff226e
commit ade22295ad
631 changed files with 92375 additions and 101763 deletions

View File

@@ -26,20 +26,19 @@ use Symfony\Component\Console\Command\Command;
class module_console_aboutAuthors extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('List authors and contributors');
$this->setDescription('List authors and contributors');
return $this;
}
return $this;
}
public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(file_get_contents(__DIR__ . '/../../../../AUTHORS'));
return 0;
}
public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(file_get_contents(__DIR__ . '/../../../../AUTHORS'));
return 0;
}
}

View File

@@ -26,20 +26,19 @@ use Symfony\Component\Console\Command\Command;
class module_console_aboutLicense extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('This program license');
$this->setDescription('This program license');
return $this;
}
return $this;
}
public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(file_get_contents(__DIR__ . '/../../../../LICENSE'));
return 0;
}
public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(file_get_contents(__DIR__ . '/../../../../LICENSE'));
return 0;
}
}

View File

@@ -25,233 +25,202 @@ 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(\bootstrap::getCore());
$registry = $appbox->get_registry();
$usr_id = $input->getOption('usr_id');
try
public function __construct($name = null)
{
$TestUser = \User_Adapter::getInstance($usr_id, $appbox);
}
catch (\Exception $e)
{
$output->writeln("<error>Wrong user !</error>");
parent::__construct($name);
return 1;
$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;
}
$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)
public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("<info>$function</info>");
if ( ! extension_loaded('phrasea2'))
printf("Missing Extension php-phrasea");
$appbox = \appbox::get_instance(\bootstrap::getCore());
$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>");
}
$Core = \bootstrap::getCore();
$configuration = $Core->getConfiguration();
$choosenConnection = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($choosenConnection);
$hostname = $connexion->get('host');
$port = $connexion->get('port');
$user = $connexion->get('user');
$password = $connexion->get('password');
$dbname = $connexion->get('dbname');
$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
, ''
, array()
);
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;
}
$Core = \bootstrap::getCore();
$configuration = $Core->getConfiguration();
$choosenConnection = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($choosenConnection);
$hostname = $connexion->get('host');
$port = $connexion->get('port');
$user = $connexion->get('user');
$password = $connexion->get('password');
$dbname = $connexion->get('dbname');
$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
, ''
, array()
);
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;
}
}

View File

@@ -25,74 +25,66 @@ 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
public function __construct($name = null)
{
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
}
catch (\Exception $e)
{
$output->writeln("<error>Invalid databox id </error>");
parent::__construct($name);
return 1;
$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;
}
try
public function execute(InputInterface $input, OutputInterface $output)
{
$field = $databox->get_meta_structure()->get_element((int) $input->getOption('meta_struct_id'));
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;
}
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;
}
}

View File

@@ -25,46 +25,43 @@ 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)
public function __construct($name = null)
{
/* @var $databox \databox */
$output->writeln(
sprintf(
"\n ---------------- \nOn databox %s (sbas_id %d) :\n"
, $databox->get_viewname()
, $databox->get_sbas_id()
)
);
parent::__construct($name);
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>' : '')
)
);
}
$this->setDescription('List all databox fields');
return $this;
}
return 0;
}
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;
}
}

View File

@@ -25,260 +25,227 @@ 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
public function __construct($name = null)
{
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
}
catch (\Exception $e)
{
$output->writeln("<error>Invalid databox id </error>");
parent::__construct($name);
return 1;
}
$this->setDescription('Merge databox structure fields');
$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->addOption(
'source'
, 'f'
, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
, 'Metadata structure ids for source'
, array()
);
$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->addOption(
'destination'
, 'd'
, InputOption::VALUE_REQUIRED
, 'Metadata structure id destination'
);
$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>"
)
$this->addOption(
'sbas_id'
, 's'
, InputOption::VALUE_REQUIRED
, 'Databox sbas_id'
);
}
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>"
)
$this->addOption(
'separator'
, ''
, InputOption::VALUE_OPTIONAL
, 'Separator for concatenation (if destination is monovalued)'
, ';'
);
}
}
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);
return $this;
}
$start = 0;
$quantity = 100;
do
public function execute(InputInterface $input, OutputInterface $output)
{
$sql = 'SELECT record_id FROM record
$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();
$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']);
foreach ($results as $row) {
$record = $databox->get_record($row['record_id']);
$datas = array();
$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);
}
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_merge($datas, $value);
}
$datas = array_unique($datas);
$datas = array_unique($datas);
if (!$destination->is_multi())
{
$datas = array(implode($separator, $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);
}
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;
$start += $quantity;
} while (count($results) > 0);
return 0;
}
while (count($results) > 0);
return 0;
}
protected function displayHelpConcatenation(OutputInterface $output)
{
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;
}
$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;
}
}

View File

@@ -25,82 +25,74 @@ 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
public function __construct($name = null)
{
$databox = \databox::get_instance((int) $input->getOption('sbas_id'));
}
catch (\Exception $e)
{
$output->writeln("<error>Invalid databox id </error>");
parent::__construct($name);
return 1;
$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;
}
try
public function execute(InputInterface $input, OutputInterface $output)
{
$field = $databox->get_meta_structure()->get_element((int) $input->getArgument('meta_struct_id'));
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;
}
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;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -25,57 +25,52 @@ use Symfony\Component\Console\Command\Command;
class module_console_schedulerStart extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('Start the scheduler');
$this->addOption(
$this->setDescription('Start the scheduler');
$this->addOption(
'nolog'
, NULL
, 1 | InputOption::VALUE_NONE
, 'do not log (scheduler) to logfile'
, NULL
);
$this->addOption(
);
$this->addOption(
'notasklog'
, NULL
, 1 | InputOption::VALUE_NONE
, 'do not log (tasks) to logfiles'
, NULL
);
$this->setHelp(
);
$this->setHelp(
"You should use launch the command and finish it with `&`"
. " to return to the console\n\n"
. "\tie : <info>bin/console scheduler:start &</info>"
);
);
return $this;
}
public function execute(InputInterface $zinput, OutputInterface $output)
{
if (!setup::is_installed())
{
$output->writeln('Phraseanet is not set up');
return 1;
return $this;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
$scheduler = new task_Scheduler();
$scheduler->run($zinput, $output); //, !$input->getOption('nolog'), !$input->getOption('notasklog'));
try
public function execute(InputInterface $zinput, OutputInterface $output)
{
$scheduler = new task_Scheduler();
$scheduler->run($output, true);
}
catch (\Exception $e)
{
return 1;
}
}
if ( ! setup::is_installed()) {
$output->writeln('Phraseanet is not set up');
return 1;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
$scheduler = new task_Scheduler();
$scheduler->run($zinput, $output); //, !$input->getOption('nolog'), !$input->getOption('notasklog'));
try {
$scheduler = new task_Scheduler();
$scheduler->run($output, true);
} catch (\Exception $e) {
return 1;
}
}
}

View File

@@ -25,54 +25,46 @@ use Symfony\Component\Console\Command\Command;
class module_console_schedulerState extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('Get scheduler state');
return $this;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if (!setup::is_installed())
public function __construct($name = null)
{
$output->writeln('Phraseanet is not set up');
parent::__construct($name);
return 1;
$this->setDescription('Get scheduler state');
return $this;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
try
public function execute(InputInterface $input, OutputInterface $output)
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$task_manager = new task_manager($appbox);
if ( ! setup::is_installed()) {
$output->writeln('Phraseanet is not set up');
$state = $task_manager->get_scheduler_state();
return 1;
}
if ($state['status'] == 'started')
{
$output->writeln(sprintf(
require_once __DIR__ . '/../../../../lib/bootstrap.php';
try {
$appbox = appbox::get_instance(\bootstrap::getCore());
$task_manager = new task_manager($appbox);
$state = $task_manager->get_scheduler_state();
if ($state['status'] == 'started') {
$output->writeln(sprintf(
'Scheduler is %s on pid %d'
, $state['schedstatus']
, $state['schedpid']
));
}
else
{
$output->writeln(sprintf('Scheduler is %s', $state['status']));
}
));
} else {
$output->writeln(sprintf('Scheduler is %s', $state['status']));
}
return 0;
return 0;
} catch (\Exception $e) {
return 1;
}
return 0;
}
catch(\Exception $e)
{
return 1;
}
return 0;
}
}

View File

@@ -25,40 +25,35 @@ use Symfony\Component\Console\Command\Command;
class module_console_schedulerStop extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('Stop the scheduler');
return $this;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if (!setup::is_installed())
public function __construct($name = null)
{
$output->writeln('Phraseanet is not set up');
parent::__construct($name);
return 1;
$this->setDescription('Stop the scheduler');
return $this;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
try
public function execute(InputInterface $input, OutputInterface $output)
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$task_manager = new task_manager($appbox);
$task_manager->set_sched_status(task_manager::STATUS_SCHED_TOSTOP);
if ( ! setup::is_installed()) {
$output->writeln('Phraseanet is not set up');
return 0;
return 1;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
try {
$appbox = appbox::get_instance(\bootstrap::getCore());
$task_manager = new task_manager($appbox);
$task_manager->set_sched_status(task_manager::STATUS_SCHED_TOSTOP);
return 0;
} catch (\Exception $e) {
return 1;
}
return 0;
}
catch (\Exception $e)
{
return 1;
}
return 0;
}
}

View File

@@ -25,138 +25,126 @@ 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)
public function __construct($name = null)
{
$index = crc32(
str_replace(
array('.', '%')
, '_'
, sprintf('%s_%s_%s_%s', $p['host'], $p['port'], $p['user'], $p['dbname'])
)
);
parent::__construct($name);
$tmp_file = $registry->get('GV_RootPath') . 'tmp/dict' . $index . '.txt';
$this->setDescription('Generate suggestions for Sphinx Search Engine');
$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 $this;
}
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)
public function execute(InputInterface $input, OutputInterface $output)
{
if (trim($line) === '')
continue;
list ( $keyword, $freq ) = explode(" ", trim($line));
define('FREQ_THRESHOLD', 10);
define('SUGGEST_DEBUG', 0);
if ($freq < FREQ_THRESHOLD || strstr($keyword, "_") !== false || strstr($keyword, "'") !== false)
continue;
$appbox = \appbox::get_instance(\bootstrap::getCore());
$registry = $appbox->get_registry();
if (ctype_digit($keyword))
{
continue;
}
if (mb_strlen($keyword) < 3)
{
continue;
}
$params = phrasea::sbas_params();
$trigrams = $this->BuildTrigrams($keyword);
foreach ($params as $sbas_id => $p) {
$index = crc32(
str_replace(
array('.', '%')
, '_'
, sprintf('%s_%s_%s_%s', $p['host'], $p['port'], $p['user'], $p['dbname'])
)
);
if ($n++)
$out .= ",\n";
$out .= "( $n, '$keyword', '$trigrams', $freq )";
$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;
}
if (trim($out) !== '')
protected function BuildTrigrams($keyword)
{
$out = "INSERT INTO suggest VALUES " . $out . ";";
$t = "__" . $keyword . "__";
$trigrams = "";
for ($i = 0; $i < strlen($t) - 2; $i ++ )
$trigrams .= substr($t, $i, 3) . " ";
return $trigrams;
}
$output->writeln(sprintf("Generated <info>%d</info> suggestions", $n));
protected function BuildDictionarySQL(OutputInterface $output, $in)
{
$out = '';
return $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;
}
}

View File

@@ -25,63 +25,61 @@ use Symfony\Component\Console\Command\Command;
class module_console_systemBackupDB extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
public function __construct($name = null)
{
parent::__construct($name);
$dir = sprintf(
$dir = sprintf(
'%s/config/'
, dirname(dirname(dirname(dirname(__DIR__))))
);
);
$this->setDescription('Backup Phraseanet Databases');
$this->setDescription('Backup Phraseanet Databases');
$this->addArgument('directory', null, 'The directory where to backup', $dir);
$this->addArgument('directory', null, 'The directory where to backup', $dir);
return $this;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if (!setup::is_installed())
{
$output->writeln('Argument must be an Id.');
return 1;
return $this;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
$output->write('Phraseanet is going to be backup...', true);
$appbox = appbox::get_instance(\bootstrap::getCore());
$ok = true;
$ok = $this->dump_base($appbox, $input, $output) && $ok;
foreach ($appbox->get_databoxes() as $databox)
public function execute(InputInterface $input, OutputInterface $output)
{
$ok = $this->dump_base($databox, $input, $output) && $ok;
if ( ! setup::is_installed()) {
$output->writeln('Argument must be an Id.');
return 1;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
$output->write('Phraseanet is going to be backup...', true);
$appbox = appbox::get_instance(\bootstrap::getCore());
$ok = true;
$ok = $this->dump_base($appbox, $input, $output) && $ok;
foreach ($appbox->get_databoxes() as $databox) {
$ok = $this->dump_base($databox, $input, $output) && $ok;
}
return (int) ! $ok;
}
return (int) !$ok;
}
protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
{
$date_obj = new DateTime();
protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
{
$date_obj = new DateTime();
$filename = sprintf(
$filename = sprintf(
'%s%s_%s.sql'
, p4string::addEndSlash($input->getArgument('directory'))
, $base->get_dbname()
, $date_obj->format('Y_m_d_H_i_s')
);
);
$output->write(sprintf('Generating %s ... ', $filename));
$output->write(sprintf('Generating %s ... ', $filename));
$command = sprintf(
$command = sprintf(
'mysqldump --host %s --port %s --user %s --password=%s'
. ' --database %s --default-character-set=utf8 > %s'
, $base->get_host()
@@ -90,24 +88,18 @@ class module_console_systemBackupDB extends Command
, $base->get_passwd()
, $base->get_dbname()
, escapeshellarg($filename)
);
);
system($command);
system($command);
if (file_exists($filename) && filesize($filename) > 0)
{
$output->writeln('OK');
if (file_exists($filename) && filesize($filename) > 0) {
$output->writeln('OK');
return true;
return true;
} else {
$output->writeln('<error>Failed</error>');
return false;
}
}
else
{
$output->writeln('<error>Failed</error>');
return false;
}
}
}

View File

@@ -26,20 +26,20 @@ use Symfony\Component\Console\Command\Command;
class module_console_systemClearCache extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('Empty cache directories, clear Memcached, Redis if avalaible');
$this->setDescription('Empty cache directories, clear Memcached, Redis if avalaible');
return $this;
}
return $this;
}
public function execute(InputInterface $input, OutputInterface $output)
{
$files = $dirs = array();
$finder = new Finder();
$finder
public function execute(InputInterface $input, OutputInterface $output)
{
$files = $dirs = array();
$finder = new Finder();
$finder
->files()
->exclude('.git')
->exclude('.svn')
@@ -48,15 +48,14 @@ class module_console_systemClearCache extends Command
, __DIR__ . '/../../../../tmp/cache_twig/'
));
$count = 1;
foreach ($finder as $file)
{
$files[$file->getPathname()] = $file->getPathname();
$count++;
}
$count = 1;
foreach ($finder as $file) {
$files[$file->getPathname()] = $file->getPathname();
$count ++;
}
$finder = new Finder();
$finder
$finder = new Finder();
$finder
->directories()
->in(array(
__DIR__ . '/../../../../tmp/cache_minify'
@@ -65,31 +64,26 @@ class module_console_systemClearCache extends Command
->exclude('.git')
->exclude('.svn');
foreach ($finder as $file)
{
$dirs[$file->getPathname()] = $file->getPathname();
printf('%4d) %s' . PHP_EOL, $count, $file->getPathname());
$count++;
foreach ($finder as $file) {
$dirs[$file->getPathname()] = $file->getPathname();
printf('%4d) %s' . PHP_EOL, $count, $file->getPathname());
$count ++;
}
foreach ($files as $file) {
unlink($file);
}
foreach ($dirs as $dir) {
rmdir($dir);
}
if (setup::is_installed()) {
$Core = \bootstrap::getCore();
$Core['CacheService']->flushAll();
}
$output->write('Finished !', true);
return 0;
}
foreach ($files as $file)
{
unlink($file);
}
foreach ($dirs as $dir)
{
rmdir($dir);
}
if(setup::is_installed())
{
$Core = \bootstrap::getCore();
$Core['CacheService']->flushAll();
}
$output->write('Finished !', true);
return 0;
}
}

View File

@@ -26,101 +26,89 @@ use Symfony\Component\Console\Command\Command;
class module_console_systemConfigCheck extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('Check the configuration');
return $this;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if (!function_exists('_'))
public function __construct($name = null)
{
$output->writeln('<error>YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET</error>');
$output->writeln('Canceled');
parent::__construct($name);
return 1;
$this->setDescription('Check the configuration');
return $this;
}
$ok = true;
if (setup::is_installed())
public function execute(InputInterface $input, OutputInterface $output)
{
$registry = registry::get_instance();
if ( ! function_exists('_')) {
$output->writeln('<error>YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET</error>');
$output->writeln('Canceled');
$output->writeln(_('*** CHECK BINARY CONFIGURATION ***'));
$ok = $this->processConstraints(setup::check_binaries($registry), $output) && $ok;
$output->writeln("");
}
else
{
$registry = new Setup_Registry();
return 1;
}
$ok = true;
if (setup::is_installed()) {
$registry = registry::get_instance();
$output->writeln(_('*** CHECK BINARY CONFIGURATION ***'));
$ok = $this->processConstraints(setup::check_binaries($registry), $output) && $ok;
$output->writeln("");
} else {
$registry = new Setup_Registry();
}
$output->writeln(_('*** FILESYSTEM CONFIGURATION ***'));
$ok = $this->processConstraints(setup::check_writability($registry), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK CACHE OPCODE ***'));
$ok = $this->processConstraints(setup::check_cache_opcode(), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK CACHE SERVER ***'));
$ok = $this->processConstraints(setup::check_cache_server(), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK PHP CONFIGURATION ***'));
$ok = $this->processConstraints(setup::check_php_configuration(), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK PHP EXTENSIONS ***'));
$ok = $this->processConstraints(setup::check_php_extension(), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK PHRASEA ***'));
$ok = $this->processConstraints(setup::check_phrasea(), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK SYSTEM LOCALES ***'));
$ok = $this->processConstraints(setup::check_system_locales(), $output) && $ok;
$output->writeln("");
$output->write('Finished !', true);
return (int) ! $ok;
}
$output->writeln(_('*** FILESYSTEM CONFIGURATION ***'));
$ok = $this->processConstraints(setup::check_writability($registry), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK CACHE OPCODE ***'));
$ok = $this->processConstraints(setup::check_cache_opcode(), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK CACHE SERVER ***'));
$ok = $this->processConstraints(setup::check_cache_server(), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK PHP CONFIGURATION ***'));
$ok = $this->processConstraints(setup::check_php_configuration(), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK PHP EXTENSIONS ***'));
$ok = $this->processConstraints(setup::check_php_extension(), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK PHRASEA ***'));
$ok = $this->processConstraints(setup::check_phrasea(), $output) && $ok;
$output->writeln("");
$output->writeln(_('*** CHECK SYSTEM LOCALES ***'));
$ok = $this->processConstraints(setup::check_system_locales(), $output) && $ok;
$output->writeln("");
$output->write('Finished !', true);
return (int)!$ok;
}
protected function processConstraints(Setup_ConstraintsIterator $constraints, OutputInterface &$output)
{
$hasError = false;
foreach ($constraints as $constraint)
protected function processConstraints(Setup_ConstraintsIterator $constraints, OutputInterface &$output)
{
if (!$hasError && !$this->processConstraint($constraint, $output))
{
$hasError = true;
}
$hasError = false;
foreach ($constraints as $constraint) {
if ( ! $hasError && ! $this->processConstraint($constraint, $output)) {
$hasError = true;
}
}
return ! $hasError;
}
return !$hasError;
}
protected function processConstraint(Setup_Constraint $constraint, OutputInterface &$output)
{
$ok = true;
if ($constraint->is_ok())
protected function processConstraint(Setup_Constraint $constraint, OutputInterface &$output)
{
$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 $ok;
}
$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 $ok;
}
}

View File

@@ -25,288 +25,259 @@ use Symfony\Component\Console\Command\Command;
class module_console_systemExport extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('Export all phraseanet records to a directory');
$this->setDescription('Export all phraseanet records to a directory');
/**
* To implement
*/
/**
* To implement
*/
// $this->addOption('useoriginalname', 'o', InputOption::VALUE_OPTIONAL
// , 'Use original name for dest files', false);
/**
* To implement
*/
/**
* To implement
*/
// $this->addOption('excludefield', 'f', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
// , 'Exclude field from XML', array());
/**
* To implement
*/
/**
* 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('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('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('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('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->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->addArgument('directory', InputOption::VALUE_REQUIRED
, 'The directory where to export');
$this->addOption('sanitize', '', InputOption::VALUE_REQUIRED
, 'Sanitize filenames. Set to 0 to disable', true);
$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');
return $this;
}
$export_directory = realpath(substr($export_directory, 0, 1) === '/' ? $export_directory : getcwd() . '/' . $export_directory . '/');
if (!$export_directory)
public function execute(InputInterface $input, OutputInterface $output)
{
throw new Exception('Export directory does not exists or is not accessible');
}
$docPerDir = max(1, (int) $input->getOption('docperdir'));
if (!is_writable($export_directory))
{
throw new Exception('Export directory is not writable');
}
/**
*
* To implement
*
$useOriginalName = !!$input->getOption('useoriginalname');
$excludeFields = $input->getOption('excludefield');
$exportStatus = !$input->getOption('excludestatus');
*
*/
$Caption = $input->getOption('caption');
/**
* Sanitize
*/
foreach ($restrictBaseIds as $key => $base_id)
{
$restrictBaseIds[$key] = (int) $base_id;
}
foreach ($restrictSbasIds as $key => $sbas_id)
{
$restrictSbasIds[$key] = (int) $sbas_id;
}
$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');
if (count($restrictSbasIds) > 0)
{
$output->writeln("Export datas from selected sbas_ids");
}
elseif (count($restrictBaseIds) > 0)
{
$output->writeln("Export datas from selected base_ids");
}
$export_directory = $input->getArgument('directory');
$appbox = \appbox::get_instance(\bootstrap::getCore());
$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 ( ! $export_directory) {
throw new Exception('Missing directory argument');
}
if ($sanitize)
{
$filename = $unicode->remove_nonazAZ09($record->get_original_name(), true, true, true);
}
else
{
$filename = $record->get_original_name();
$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');
}
$this->generateDefinitiveFilename($in_dir_files, $filename);
$output_file = $current_dir . $filename;
if (!$this->processRecords($record, $output_file, $Caption))
{
$errors++;
if ( ! is_writable($export_directory)) {
throw new Exception('Export directory is not writable');
}
$done++;
/**
* Sanitize
*/
foreach ($restrictBaseIds as $key => $base_id) {
$restrictBaseIds[$key] = (int) $base_id;
}
foreach ($restrictSbasIds as $key => $sbas_id) {
$restrictSbasIds[$key] = (int) $sbas_id;
}
$output->write(sprintf("\r#%" . $l . "d record remaining", $current_total - $done));
}
$output->writeln(" | " . $current_total . " records done\n");
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(\bootstrap::getCore());
$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;
}
$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))
protected function generateDefinitiveFilename(array &$existing, &$filename)
{
$pathinfo = pathinfo($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++;
$definitive_filename = $pathinfo['filename'] . '_' . $suffix .
(isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : '');
$suffix ++;
}
$existing[$filename] = $filename;
$filename = $definitive_filename;
return;
}
$existing[$filename] = $filename;
$filename = $definitive_filename;
return;
}
protected function processRecords(\record_adapter $record, $outfile, $caption)
{
try
protected function processRecords(\record_adapter $record, $outfile, $caption)
{
$file = new system_file($record->get_subdef('document')->get_pathfile());
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 = $record->get_caption()->serialize(caption_record::SERIALIZE_XML);
$xml_file = dirname($outfile) . '/' . $pathinfo['filename'] . '.xml';
file_put_contents($xml_file, $xml);
break;
default:
break;
}
return true;
}
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 = $record->get_caption()->serialize(caption_record::SERIALIZE_XML);
$xml_file = dirname($outfile) . '/' . $pathinfo['filename'] . '.xml';
file_put_contents($xml_file, $xml);
break;
default:
break;
}
return true;
}
}

View File

@@ -26,126 +26,107 @@ use Symfony\Component\Console\Command\Command;
class module_console_systemMailCheck extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('Check if email addresses are unique (mandatory since 3.5)');
$this->addOption('list'
$this->setDescription('Check if email addresses are unique (mandatory since 3.5)');
$this->addOption('list'
, 'l'
, null
, 'List all bad accounts instead of the interactive mode'
);
);
return $this;
}
public function execute(InputInterface $input, OutputInterface $output)
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$output->writeln("Processing...");
$bad_users = User_Adapter::get_wrong_email_users($appbox);
foreach ($bad_users as $email => $users)
{
if ($input->getOption('list'))
{
$this->write_infos($email, $users, $output, $appbox);
}
elseif ($this->manage_group($email, $users, $output, $appbox) === false)
{
break;
}
$output->writeln("");
return $this;
}
$output->write('Finished !', true);
return 0;
}
protected function manage_group($email, $users, $output, $appbox)
{
$is_stopped = false;
while (!$is_stopped)
public function execute(InputInterface $input, OutputInterface $output)
{
$this->write_infos($email, $users, $output, $appbox);
$dialog = $this->getHelperSet()->get('dialog');
$appbox = appbox::get_instance(\bootstrap::getCore());
do
{
$question = '<question>What should I do ? '
. 'continue (C), detach from mail (d), or stop (s)</question>';
$output->writeln("Processing...");
$continue = mb_strtolower($dialog->ask($output, $question, 'C'));
}
while (!in_array($continue, array('c', 'd', 's')));
$bad_users = User_Adapter::get_wrong_email_users($appbox);
foreach ($bad_users as $email => $users) {
if ($input->getOption('list')) {
$this->write_infos($email, $users, $output, $appbox);
} elseif ($this->manage_group($email, $users, $output, $appbox) === false) {
break;
}
$output->writeln("");
}
$output->write('Finished !', true);
return 0;
}
protected function manage_group($email, $users, $output, $appbox)
{
$is_stopped = false;
while ( ! $is_stopped) {
$this->write_infos($email, $users, $output, $appbox);
$dialog = $this->getHelperSet()->get('dialog');
do {
$question = '<question>What should I do ? '
. 'continue (C), detach from mail (d), or stop (s)</question>';
$continue = mb_strtolower($dialog->ask($output, $question, 'C'));
} while ( ! in_array($continue, array('c', 'd', 's')));
if ($continue == 's')
{
return false;
}
elseif ($continue == 'c')
{
if ($continue == 's') {
return false;
} elseif ($continue == 'c') {
return true;
} elseif ($continue == 'd') {
$dialog = $this->getHelperSet()->get('dialog');
$id = $dialog->ask($output, '<question>Which id ?</question>', '');
try {
$tmp_user = User_Adapter::getInstance($id, $appbox);
if ($tmp_user->get_email() != $email) {
throw new Exception('Invalid user');
}
$tmp_user->set_email(null);
unset($users[$id]);
} catch (Exception $e) {
$output->writeln('<error>Wrong id</error>');
}
}
if (count($users) <= 1) {
$output->writeln(sprintf("<info>\n%s fixed !</info>", $email));
$is_stopped = true;
}
}
return true;
}
elseif ($continue == 'd')
{
$dialog = $this->getHelperSet()->get('dialog');
$id = $dialog->ask($output, '<question>Which id ?</question>', '');
try
{
$tmp_user = User_Adapter::getInstance($id, $appbox);
if ($tmp_user->get_email() != $email)
{
throw new Exception('Invalid user');
}
$tmp_user->set_email(null);
unset($users[$id]);
}
catch (Exception $e)
{
$output->writeln('<error>Wrong id</error>');
}
}
if (count($users) <= 1)
{
$output->writeln(sprintf("<info>\n%s fixed !</info>", $email));
$is_stopped = true;
}
}
return true;
}
protected function write_infos($email, $users, $output, $appbox)
{
$output->writeln($email);
foreach ($users as $user)
protected function write_infos($email, $users, $output, $appbox)
{
$output->writeln(
sprintf(
"\t %5d %40s %s"
, $user->get_id()
, $user->get_display_name()
, $user->get_last_connection()->format('Y m d')
)
);
}
}
$output->writeln($email);
foreach ($users as $user) {
$output->writeln(
sprintf(
"\t %5d %40s %s"
, $user->get_id()
, $user->get_display_name()
, $user->get_last_connection()->format('Y m d')
)
);
}
}
}

View File

@@ -37,22 +37,21 @@ class module_console_systemTemplateGenerator extends Command
public function execute(InputInterface $input, OutputInterface $output)
{
$tplDirs = array(
realpath(__DIR__ . '/../../../../templates/web/'),
realpath(__DIR__ . '/../../../../templates/mobile/')
realpath(__DIR__ . '/../../../../templates/web/'),
realpath(__DIR__ . '/../../../../templates/mobile/')
);
$n_ok = $n_error = 0;
$n_ok = $n_error = 0;
foreach ($tplDirs as $tplDir)
{
foreach ($tplDirs as $tplDir) {
$tmpDir = __DIR__ . '/../../../../tmp/cache_twig/';
$loader = new Twig_Loader_Filesystem($tplDir);
$twig = new Twig_Environment($loader, array(
'cache' => $tmpDir,
'auto_reload' => true
));
'cache' => $tmpDir,
'auto_reload' => true
));
$twig->addExtension(new Twig_Extensions_Extension_I18n());
@@ -93,16 +92,12 @@ class module_console_systemTemplateGenerator extends Command
$finder = new Symfony\Component\Finder\Finder();
foreach ($finder->files()->in(array($tplDir)) as $file)
{
try
{
foreach ($finder->files()->in(array($tplDir)) as $file) {
try {
$twig->loadTemplate(str_replace($tplDir, '', $file->getPathname()));
$output->writeln('' . $file . '');
$n_ok ++;
}
catch (Exception $e)
{
} catch (Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$n_error ++;
}
@@ -112,8 +107,7 @@ class module_console_systemTemplateGenerator extends Command
$output->writeln("");
$output->write(sprintf('%d templates generated. ', $n_ok));
if ($n_error > 0)
{
if ($n_error > 0) {
$output->write(sprintf('<error>%d templates failed.</error>', $n_error));
}
@@ -121,5 +115,4 @@ class module_console_systemTemplateGenerator extends Command
return $n_error;
}
}

View File

@@ -26,92 +26,73 @@ use Symfony\Component\Console\Command\Command;
class module_console_systemUpgrade extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('Upgrade Phraseanet to the lastest version');
return $this;
}
public function execute(InputInterface $input, OutputInterface $output)
{
$Core = \bootstrap::getCore();
if (!setup::is_installed())
public function __construct($name = null)
{
parent::__construct($name);
$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 ?');
$this->setDescription('Upgrade Phraseanet to the lastest version');
$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')
{
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');
}
return $this;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
$output->write('Phraseanet is going to be upgraded', true);
$dialog = $this->getHelperSet()->get('dialog');
do
public function execute(InputInterface $input, OutputInterface $output)
{
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Continuer ?') . ' (Y/n)</question>', 'Y'));
}
while (!in_array($continue, array('y', 'n')));
$Core = \bootstrap::getCore();
if ( ! setup::is_installed()) {
$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 ?');
if ($continue == 'y')
{
try
{
$Core = \bootstrap::getCore();
$output->write('<info>Upgrading...</info>', true);
$appbox = appbox::get_instance($Core);
$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 (count(User_Adapter::get_wrong_email_users($appbox)) > 0)
{
return $output->writeln(sprintf('<error>You have to fix your database before upgrade with the system:mailCheck command </error>'));
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');
}
}
$upgrader = new Setup_Upgrade($appbox);
$advices = $appbox->forceUpgrade($upgrader);
}
catch (\Exception $e)
{
require_once __DIR__ . '/../../../../lib/bootstrap.php';
$output->writeln(sprintf('<error>An error occured while upgrading : %s </error>', $e->getMessage()));
}
$output->write('Phraseanet is going to be upgraded', true);
$dialog = $this->getHelperSet()->get('dialog');
do {
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Continuer ?') . ' (Y/n)</question>', 'Y'));
} while ( ! in_array($continue, array('y', 'n')));
if ($continue == 'y') {
try {
$Core = \bootstrap::getCore();
$output->write('<info>Upgrading...</info>', true);
$appbox = appbox::get_instance($Core);
if (count(User_Adapter::get_wrong_email_users($appbox)) > 0) {
return $output->writeln(sprintf('<error>You have to fix your database before upgrade with the system:mailCheck command </error>'));
}
$upgrader = new Setup_Upgrade($appbox);
$advices = $appbox->forceUpgrade($upgrader);
} catch (\Exception $e) {
$output->writeln(sprintf('<error>An error occured while upgrading : %s </error>', $e->getMessage()));
}
} else {
$output->write('<info>Canceled</info>', true);
}
$output->write('Finished !', true);
return 0;
}
else
{
$output->write('<info>Canceled</info>', true);
}
$output->write('Finished !', true);
return 0;
}
}

View File

@@ -26,56 +26,49 @@ use Symfony\Component\Console\Command\Command;
class module_console_tasklist extends Command
{
public function __construct($name = null)
{
parent::__construct($name);
$this->setDescription('List tasks');
return $this;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if (!setup::is_installed())
public function __construct($name = null)
{
$output->writeln('Phraseanet is not set up');
parent::__construct($name);
return 1;
$this->setDescription('List tasks');
return $this;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
try
public function execute(InputInterface $input, OutputInterface $output)
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$task_manager = new task_manager($appbox);
$tasks = $task_manager->get_tasks();
if ( ! setup::is_installed()) {
$output->writeln('Phraseanet is not set up');
if (count($tasks) === 0)
{
$output->writeln('No tasks on your install !');
}
return 1;
}
foreach ($tasks as $task)
{
$this->print_task($task, $output);
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
return 0;
try {
$appbox = appbox::get_instance(\bootstrap::getCore());
$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) {
$this->print_task($task, $output);
}
return 0;
} catch (\Exception $e) {
return 1;
}
}
catch (\Exception $e)
protected function print_task(task_abstract $task, OutputInterface &$output)
{
return 1;
$message = $task->get_task_id() . "\t" . ($task->get_status() ) . "\t" . $task->get_title();
$output->writeln($message);
return $this;
}
}
protected function print_task(task_abstract $task, OutputInterface &$output)
{
$message = $task->get_task_id() . "\t" . ($task->get_status() ) . "\t" . $task->get_title();
$output->writeln($message);
return $this;
}
}

View File

@@ -25,117 +25,105 @@ use Symfony\Component\Console\Command\Command;
class module_console_taskrun extends Command
{
private $task;
private $shedulerPID;
private $task;
private $shedulerPID;
public function __construct($name = null)
{
parent::__construct($name);
$this->task = NULL;
$this->shedulerPID = NULL;
$this->addArgument('task_id', InputArgument::REQUIRED, 'The task_id to run');
$this->addOption(
'runner'
, 'r'
, InputOption::VALUE_REQUIRED
, 'The name of the runner (manual, scheduler...)'
, task_abstract::RUNNER_MANUAL
);
$this->addOption(
'nolog'
, NULL
, 1 | InputOption::VALUE_NONE
, 'do not log to logfile'
, NULL
);
$this->setDescription('Run task');
return $this;
}
function sig_handler($signo)
{
if ($this->task)
public function __construct($name = null)
{
$this->task->log(sprintf("signal %s received", $signo));
if ($signo == SIGTERM)
$this->task->set_running(false);
}
}
parent::__construct($name);
public function execute(InputInterface $input, OutputInterface $output)
{
if (!setup::is_installed())
{
$output->writeln('Phraseanet is not set up');
$this->task = NULL;
$this->shedulerPID = NULL;
return 1;
$this->addArgument('task_id', InputArgument::REQUIRED, 'The task_id to run');
$this->addOption(
'runner'
, 'r'
, InputOption::VALUE_REQUIRED
, 'The name of the runner (manual, scheduler...)'
, task_abstract::RUNNER_MANUAL
);
$this->addOption(
'nolog'
, NULL
, 1 | InputOption::VALUE_NONE
, 'do not log to logfile'
, NULL
);
$this->setDescription('Run task');
return $this;
}
$task_id = (int) $input->getArgument('task_id');
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id')))
throw new \RuntimeException('Argument must be an Id.');
$appbox = \appbox::get_instance(\bootstrap::getCore());
$task_manager = new task_manager($appbox);
$this->task = $task_manager->get_task($task_id);
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
function sig_handler($signo)
{
$runner = task_abstract::RUNNER_MANUAL;
}
else
{
$runner = task_abstract::RUNNER_SCHEDULER;
$registry = $appbox->get_registry();
$schedFile = $registry->get('GV_RootPath') . 'tmp/locks/scheduler.lock';
if (file_exists($schedFile))
$this->shedulerPID = (int) (trim(file_get_contents($schedFile)));
}
register_tick_function(array($this, 'tick_handler'), true);
declare(ticks = 1);
pcntl_signal(SIGTERM, array($this, 'sig_handler'));
$this->task->run($runner, $input, $output);
$this->task->log(sprintf("%s [%d] taskrun : returned from 'run()', get_status()=%s \n", __FILE__, __LINE__, $this->task->get_status()));
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
{
$runner = task_abstract::RUNNER_MANUAL;
}
}
public function tick_handler()
{
static $start = FALSE;
if ($start === FALSE)
{
$start = time();
}
if (time() - $start > 0)
{
if ($this->shedulerPID)
{
if (!posix_kill($this->shedulerPID, 0))
{
if (method_exists($this->task, 'signal'))
$this->task->signal('SIGNAL_SCHEDULER_DIED');
else
$this->task->set_status(task_abstract::STATUS_TOSTOP);
if ($this->task) {
$this->task->log(sprintf("signal %s received", $signo));
if ($signo == SIGTERM)
$this->task->set_running(false);
}
}
$start = time();
}
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! setup::is_installed()) {
$output->writeln('Phraseanet is not set up');
return 1;
}
$task_id = (int) $input->getArgument('task_id');
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id')))
throw new \RuntimeException('Argument must be an Id.');
$appbox = \appbox::get_instance(\bootstrap::getCore());
$task_manager = new task_manager($appbox);
$this->task = $task_manager->get_task($task_id);
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) {
$runner = task_abstract::RUNNER_MANUAL;
} else {
$runner = task_abstract::RUNNER_SCHEDULER;
$registry = $appbox->get_registry();
$schedFile = $registry->get('GV_RootPath') . 'tmp/locks/scheduler.lock';
if (file_exists($schedFile))
$this->shedulerPID = (int) (trim(file_get_contents($schedFile)));
}
register_tick_function(array($this, 'tick_handler'), true);
declare(ticks = 1);
pcntl_signal(SIGTERM, array($this, 'sig_handler'));
$this->task->run($runner, $input, $output);
$this->task->log(sprintf("%s [%d] taskrun : returned from 'run()', get_status()=%s \n", __FILE__, __LINE__, $this->task->get_status()));
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) {
$runner = task_abstract::RUNNER_MANUAL;
}
}
public function tick_handler()
{
static $start = FALSE;
if ($start === FALSE) {
$start = time();
}
if (time() - $start > 0) {
if ($this->shedulerPID) {
if ( ! posix_kill($this->shedulerPID, 0)) {
if (method_exists($this->task, 'signal'))
$this->task->signal('SIGNAL_SCHEDULER_DIED');
else
$this->task->set_status(task_abstract::STATUS_TOSTOP);
}
}
$start = time();
}
}
}