/** * * @param int $sbas_id * @return status */ private function __construct(Application $app, $sbas_id) { $this->status = []; $path = $url = false; $sbas_params = phrasea::sbas_params($app); if (!isset($sbas_params[$sbas_id])) { return; } $uniqid = md5(implode('-', [$sbas_params[$sbas_id]["host"], $sbas_params[$sbas_id]["port"], $sbas_params[$sbas_id]["dbname"]])); $path = $this->path = $app['root.path'] . "/config/status/" . $uniqid; $url = $this->url = "/custom/status/" . $uniqid; $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); $xmlpref = $databox->get_structure(); $sxe = simplexml_load_string($xmlpref); if ($sxe !== false) { foreach ($sxe->statbits->bit as $sb) { $bit = (int) $sb["n"]; if ($bit < 4 && $bit > 31) { continue; } $this->status[$bit]["labeloff"] = (string) $sb['labelOff']; $this->status[$bit]["labelon"] = (string) $sb['labelOn']; foreach ($app['locales.available'] as $code => $language) { $this->status[$bit]['labels_on'][$code] = null; $this->status[$bit]['labels_off'][$code] = null; } foreach ($sb->label as $label) { $this->status[$bit]['labels_' . $label['switch']][(string) $label['code']] = (string) $label; } foreach ($app['locales.available'] as $code => $language) { $this->status[$bit]['labels_on_i18n'][$code] = '' !== trim($this->status[$bit]['labels_on'][$code]) ? $this->status[$bit]['labels_on'][$code] : $this->status[$bit]["labelon"]; $this->status[$bit]['labels_off_i18n'][$code] = '' !== trim($this->status[$bit]['labels_off'][$code]) ? $this->status[$bit]['labels_off'][$code] : $this->status[$bit]["labeloff"]; } $this->status[$bit]["img_off"] = null; $this->status[$bit]["img_on"] = null; if (is_file($path . "-stat_" . $bit . "_0.gif")) { $this->status[$bit]["img_off"] = $url . "-stat_" . $bit . "_0.gif?etag=" . md5_file($path . "-stat_" . $bit . "_0.gif"); $this->status[$bit]["path_off"] = $path . "-stat_" . $bit . "_0.gif"; } if (is_file($path . "-stat_" . $bit . "_1.gif")) { $this->status[$bit]["img_on"] = $url . "-stat_" . $bit . "_1.gif?etag=" . md5_file($path . "-stat_" . $bit . "_1.gif"); $this->status[$bit]["path_on"] = $path . "-stat_" . $bit . "_1.gif"; } $this->status[$bit]["searchable"] = isset($sb['searchable']) ? (int) $sb['searchable'] : 0; $this->status[$bit]["printable"] = isset($sb['printable']) ? (int) $sb['printable'] : 0; } } ksort($this->status); return $this; }
/** * @param Application $app * @param int $sbas_id * @param array $row */ public function __construct(Application $app, $sbas_id, array $row) { assert(is_int($sbas_id)); assert($sbas_id > 0); $this->id = $sbas_id; $connectionConfigs = phrasea::sbas_params($app); if (!isset($connectionConfigs[$sbas_id])) { throw new NotFoundHttpException(sprintf('databox %d not found', $sbas_id)); } $connectionConfig = $connectionConfigs[$sbas_id]; $connection = $app['db.provider']($connectionConfig); $connectionSettings = new ConnectionSettings($connectionConfig['host'], $connectionConfig['port'], $connectionConfig['dbname'], $connectionConfig['user'], $connectionConfig['password']); $versionRepository = new DataboxVersionRepository($connection); parent::__construct($app, $connection, $connectionSettings, $versionRepository); $this->loadFromRow($row); }
protected function doExecute(InputInterface $input, OutputInterface $output) { define('FREQ_THRESHOLD', 10); define('SUGGEST_DEBUG', 0); $params = phrasea::sbas_params($this->container); foreach ($params as $sbas_id => $p) { $index = sprintf("%u", crc32(str_replace(['.', '%'], '_', sprintf('%s_%s_%s_%s', $p['host'], $p['port'], $p['user'], $p['dbname'])))); $tmp_file = $this->container['root.path'] . '/tmp/dict' . $index . '.txt'; $databox = $this->getService('phraseanet.appbox')->get_databox($sbas_id); $output->writeln("process Databox " . $databox->get_label($this->container['locale']) . " / {$index}\n"); if (!is_executable("/usr/local/bin/indexer")) { $output->writeln("<error>'/usr/local/bin/indexer' is not executable</error>"); return 1; } $builder = ProcessBuilder::create(['/usr/local/bin/indexer']); $builder->add('metadatas' . $index)->add('--buildstops')->add($tmp_file)->add(1000000)->add('--buildfreqs'); $builder->getProcess()->run(); if (!file_exists($tmp_file)) { $output->writeln("<error> file '" . $tmp_file . "' does not exist</error>"); return 1; } try { $connbas = $databox->get_connection()->connect(); } 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; }
public function __construct(Application $app, $sbas_id) { assert(is_int($sbas_id)); assert($sbas_id > 0); $this->app = $app; $this->id = $sbas_id; $connection_params = phrasea::sbas_params($this->app); if (!isset($connection_params[$sbas_id])) { throw new NotFoundHttpException(sprintf('databox %d not found', $sbas_id)); } $this->connection = $app['dbal.provider']->get(['host' => $connection_params[$sbas_id]['host'], 'port' => $connection_params[$sbas_id]['port'], 'user' => $connection_params[$sbas_id]['user'], 'password' => $connection_params[$sbas_id]['pwd'], 'dbname' => $connection_params[$sbas_id]['dbname']]); $this->host = $connection_params[$sbas_id]['host']; $this->port = $connection_params[$sbas_id]['port']; $this->user = $connection_params[$sbas_id]['user']; $this->passwd = $connection_params[$sbas_id]['pwd']; $this->dbname = $connection_params[$sbas_id]['dbname']; return $this; }