diff --git a/lib/classes/module/console/checkExtension.class.php b/lib/classes/module/console/checkExtension.class.php new file mode 100644 index 0000000000..f7c5571bc7 --- /dev/null +++ b/lib/classes/module/console/checkExtension.class.php @@ -0,0 +1,248 @@ +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("Wrong user !"); + + return 1; + } + + $output->writeln( + sprintf( + "\nWill do the check with user %s (%s)\n" + , $TestUser->get_display_name() + , $TestUser->get_email() + ) + ); + + $output->writeln("PHRASEA FUNCTIONS"); + + foreach (get_extension_funcs("phrasea2") as $function) + { + $output->writeln("$function"); + } + + require (__DIR__ . '/../../../../config/connexion.inc'); + + + $output->writeln("\n-- phrasea_conn --"); + + if (phrasea_conn($hostname, $port, $user, $password, $dbname) !== true) + { + $output->writeln("Failed ! got no connection"); + + return 1; + } + else + { + $output->writeln("Succes ! 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("Succes ! got session id $sessid"); + } + else + { + $output->writeln("Failed ! 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("Succes ! got session "); + } + else + { + $output->writeln("Failed ! got no session "); + + return 1; + } + + $output->writeln("\n-- phrasea_clear_cache --"); + + $ret = phrasea_clear_cache($sessid); + + if ($sessid) + { + $output->writeln("Succes ! got session "); + } + else + { + $output->writeln("Failed ! 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("Succes ! got result on sbas_id " . $base["sbas_id"]); + } + else + { + $output->writeln("Failed ! 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 $nbanswers answers"); + + $output->writeln("\n-- phrasea_fetch_results --"); + + $rs = phrasea_fetch_results($sessid, $usr_id, 1, true, '[[em]]', '[[/em]]'); + + if ($rs) + { + $output->writeln("Succes ! got result "); + } + else + { + $output->writeln("Failed ! got no result "); + + return 1; + } + + $output->writeln("\n-- phrasea_close_session --"); + + $rs = phrasea_close_session($sessid); + + if ($rs) + { + $output->writeln("Succes ! closed ! "); + } + else + { + $output->writeln("Failed ! not closed "); + + return 1; + } + + return 0; + } + +} \ No newline at end of file