/** * Builds the configured DFSBackend handler * @return eZDFSFileHandlerDFSBackendInterface */ public static function build() { if (!isset(self::$instance)) { self::$instance = self::buildHandler(eZINI::instance('file.ini')->variable('eZDFSClusteringSettings', 'DFSBackend')); } return self::$instance; }
/** * Reimplement parent's method to make use of a tracing dfs backend class */ public function _connect() { $siteINI = eZINI::instance('site.ini'); // DB Connection setup // This part is not actually required since _connect will only be called // once, but it is useful to run the unit tests. So be it. // @todo refactor this using eZINI::setVariable in unit tests if (parent::$dbparams === null) { $fileINI = eZINI::instance('file.ini'); parent::$dbparams = array(); parent::$dbparams['host'] = $fileINI->variable('eZDFSClusteringSettings', 'DBHost'); $dbPort = $fileINI->variable('eZDFSClusteringSettings', 'DBPort'); parent::$dbparams['port'] = $dbPort !== '' ? $dbPort : null; parent::$dbparams['socket'] = $fileINI->variable('eZDFSClusteringSettings', 'DBSocket'); parent::$dbparams['dbname'] = $fileINI->variable('eZDFSClusteringSettings', 'DBName'); parent::$dbparams['user'] = $fileINI->variable('eZDFSClusteringSettings', 'DBUser'); parent::$dbparams['pass'] = $fileINI->variable('eZDFSClusteringSettings', 'DBPassword'); parent::$dbparams['max_connect_tries'] = $fileINI->variable('eZDFSClusteringSettings', 'DBConnectRetries'); parent::$dbparams['max_execute_tries'] = $fileINI->variable('eZDFSClusteringSettings', 'DBExecuteRetries'); parent::$dbparams['sql_output'] = $siteINI->variable("DatabaseSettings", "SQLOutput") == "enabled"; parent::$dbparams['cache_generation_timeout'] = $siteINI->variable("ContentSettings", "CacheGenerationTimeout"); } $serverString = parent::$dbparams['host']; if (parent::$dbparams['socket']) { $serverString .= ':' . parent::$dbparams['socket']; } elseif (parent::$dbparams['port']) { $serverString .= ':' . parent::$dbparams['port']; } $maxTries = parent::$dbparams['max_connect_tries']; $tries = 0; eZPerfLogger::accumulatorStart('mysql_cluster_connect', 'MySQL Cluster', 'Cluster database connection'); while ($tries < $maxTries) { if ($this->db = mysqli_connect(parent::$dbparams['host'], parent::$dbparams['user'], parent::$dbparams['pass'], parent::$dbparams['dbname'], parent::$dbparams['port'])) { break; } ++$tries; } eZPerfLogger::accumulatorStop('mysql_cluster_connect'); if (!$this->db) { throw new eZClusterHandlerDBNoConnectionException($serverString, self::$dbparams['user'], self::$dbparams['pass'], 'Error ' . mysqli_connect_errno() . ': ' . mysqli_connect_error()); } /*if ( !mysql_select_db( parent::$dbparams['dbname'], $this->db ) ) throw new eZClusterHandlerDBNoDatabaseException( parent::$dbparams['dbname'] );*/ // DFS setup $this->dfsbackend = eZDFSFileHandlerBackendFactory::build(); $charset = trim($siteINI->variable('DatabaseSettings', 'Charset')); if ($charset === '') { $charset = eZTextCodec::internalCharset(); } if ($charset) { if (!mysqli_set_charset($this->db, eZMySQLCharset::mapTo($charset))) { $this->_fail("Failed to set Database charset to {$charset}."); } } }
/** * Builds a registry using either the provided configuration, or settings from self::getConfiguration * @return self */ public static function build() { $ini = eZINI::instance('file.ini'); $defaultHandler = eZDFSFileHandlerBackendFactory::buildHandler($ini->variable('DispatchableDFS', 'DefaultBackend')); $pathHandlers = array(); foreach ($ini->variable('DispatchableDFS', 'PathBackends') as $supportedPath => $backendClass) { // @todo Make it possible to use a Symfony2 service $pathHandlers[$supportedPath] = eZDFSFileHandlerBackendFactory::buildHandler($backendClass); } return new static($defaultHandler, $pathHandlers); }
if ($limit) { $limit[0] += $limit[1]; } else { $loopRun = false; } unset($files); } $cli->output('Done'); } if ($checkDFS) { if ($delete) { $cli->output('Deleting the files on the DFS share that are not registered in the database...'); } else { $cli->output('Checking files on the DFS share...'); } $dfsBackend = eZDFSFileHandlerBackendFactory::build(); foreach ($dfsBackend->getFilesList($checkPath) as $filePathName) { try { if (!$fileHandler->fileExists($filePathName)) { $cli->output(' - ' . $filePathName); if ($delete) { $dfsBackend->delete($filePathName); } } } catch (Exception $e) { abort("DFS Backend error, aborting.\n" . $e->getMessage()); } usleep($pause); } $cli->output('Done'); }
/** * Tests that the default DFS Backend gets build normally. */ public function testBuildDFSBackend() { self::assertInstanceOf('eZDFSFileHandlerDFSBackend', eZDFSFileHandlerBackendFactory::build()); }