/** * Inserts one or more sql files into the test database * * @param eZDBInterface $db * @param array $sqlFiles array( array( string => string ) ) * @return bool */ public static function insertSqlData(eZDBInterface $db, $sqlFiles) { if (!is_array($sqlFiles) or count($sqlFiles) <= 0) { return false; } foreach ($sqlFiles as $sqlFile) { if (is_array($sqlFile)) { $success = $db->insertFile($sqlFile[0], $sqlFile[1]); } else { $success = $db->insertFile(dirname($sqlFile), basename($sqlFile), false); } if (!$success) { eZDebug::writeWarning("Failed inserting SQL file {$sqlFile['0']} ... {$sqlFile['1']}", __METHOD__); } } return true; }
/** * Inserts one or more sql files into the test database * * @param eZDBInterface $db * @param array $sqlFiles array( array( string => string ) ) * @return bool */ public static function insertSqlData(eZDBInterface $db, $sqlFiles) { if (!is_array($sqlFiles) or count($sqlFiles) <= 0) { return false; } foreach ($sqlFiles as $sqlFile) { if (is_array($sqlFile)) { $success = $db->insertFile($sqlFile[0], $sqlFile[1]); } else { $success = $db->insertFile(dirname($sqlFile), basename($sqlFile), false); } if (!$success) { return false; } } return true; }
/** * @todo optimize db query: use a prepared statement */ public function checkFiles($doDelete = false, $returnData = false) { $violations = array(); $dir = $this->clusterizeDir(eZSys::storageDirectory() . '/original'); if (!is_dir($dir)) { return $violations; } $dir = realpath($dir); foreach (glob($dir . '/*', GLOB_ONLYDIR) as $storageDir) { if (in_array(basename($storageDir), array('.', '..'))) { continue; } foreach (glob($storageDir . '/*') as $storageFile) { if (!is_file($storageFile)) { continue; } $fileName = basename($storageFile); $dirName = basename($storageDir); $sql1 = "SELECT COUNT(*) AS found FROM ezbinaryfile " . "WHERE filename = '" . $this->db->escapeString($fileName) . "' AND mime_type LIKE '" . $this->db->escapeString($dirName) . "/%'"; $sql2 = "SELECT COUNT(*) AS found FROM ezmedia " . "WHERE filename = '" . $this->db->escapeString($fileName) . "' AND mime_type LIKE '" . $this->db->escapeString($dirName) . "/%'"; $results1 = $this->db->arrayQuery($sql1); $results2 = $this->db->arrayQuery($sql2); if ($results1[0]['found'] == 0 && $results2[0]['found'] == 0) { if (isset($violations['violatingFileCount'])) { $violations['violatingFileCount']++; } else { $violations['violatingFileCount'] = 1; } if ($returnData) { $violations['violatingFiles'][] = $storageFile; } if ($doDelete) { unlink($storageFile); } } /*else { echo "OK: $storageFile\n"; }*/ } } return $violations; }
function dropTempTable( $dropTableQuery = '', $server = self::SERVER_SLAVE ) { $dropTableQuery = str_ireplace( 'DROP TABLE', 'DROP TEMPORARY TABLE', $dropTableQuery ); parent::dropTempTable( $dropTableQuery, $server ); }
public function checkCustomQuery($sql) { return $this->db->arrayQuery($sql); }
/** * Sets application localized url to NULL and sets its visibility as private * @param int $appId Id of application to be hidden * @param string $clusterIdentifier Identifier of cluster * @param eZDBInterface $db db to be used * @param eZCLI $cli command line to be used * @param boolean $dryRun Decides whether queries should be outputed to CLI or be used to update the DB */ function hideFromApplicationLocalized( $appId, $clusterIdentifier, eZDBInterface $db, eZCLI $cli, $dryRun = false ) { global $appId, $clusterIdentifier, $db, $eZDB, $cli, $dryRun; $update = sprintf( "UPDATE mm_application_localized SET url = NULL, restriction_level = 'private' WHERE application_id='%s' AND cluster_identifier='%s'", $db->escapeString($appId), $db->escapeString($clusterIdentifier) ); if ( !$dryRun ) { $db->query( $update ); } else { $cli->output( $update ); } }
/** * @param eZCLI $cli * @param eZDBInterface $db * @param string $cronPart * @param int $maxRetries * @return int offset to use or -1 if an error occures */ function computeOffsetByFork ( $cli, $db, $cronPart, $maxRetries ) { // Normal case if (!preg_match('#^[a-zA-Z_]+(\d)#', $cronPart, $match)) { return 0; } $ezfindIni = eZINI::instance('ezfind.ini'); $maxForks = $ezfindIni->variable('IndexOptions', 'MaxPendingForkCount'); $matchOffset = $match[1] - 1; if ( $matchOffset > $maxForks ) { $cli->output( "Ini setting states you can't run more than $maxForks forks, you try to run fork #" . ($matchOffset + 1) ); return -1; } $countQuery = "SELECT count(id) as nb_pending FROM ezpending_actions WHERE action = 'index_object' AND ( param_int IS NULL OR param_int <= $maxRetries )"; $result = $db->arrayQuery($countQuery); if ( !$result || !isset($result[0]['nb_pending'])) { $cli->error("Mysql unexpected error. Script will be stopped."); return -1; } $forkInterval = $ezfindIni->variable('IndexOptions', 'MinPendingForkInterval'); $pendingCount = $result[0]['nb_pending']; $forkMinCount = $matchOffset * $forkInterval; if ($pendingCount < $forkMinCount) { $cli->warning( "Trying to run pending fork #$matchOffset but we have less than $forkMinCount pending objects. Script will be stopped."); return -1; } $offset = max($forkMinCount, round($pendingCount/$maxForks) * $matchOffset); $cli->output( "Fork #" . ($matchOffset + 1) . " starting at offset #$offset"); return $offset; }
/** * Returns the short attribute name (alias) if it's defined, given attribute name otherwise * * @param eZDBInterface $db * @param array $def A definition array of all fields, table name and sorting (see {@link eZPersistentObject::definition()} for more info) * @param string $attrName * @return string */ public static function getShortAttributeName($db, $def, $attrName) { $fields = $def['fields']; if ($db->useShortNames() && isset($fields[$attrName]) && array_key_exists('short_name', $fields[$attrName]) && $fields[$attrName]['short_name']) { return $fields[$attrName]['short_name']; } return $attrName; }
function __construct($parameters) { parent::__construct($parameters); if (!extension_loaded('pgsql')) { if (function_exists('eZAppendWarningItem')) { eZAppendWarningItem(array('error' => array('type' => 'ezdb', 'number' => eZDBInterface::ERROR_MISSING_EXTENSION), 'text' => 'PostgreSQL extension was not found, the DB handler will not be initialized.')); $this->IsConnected = false; } eZDebug::writeWarning('PostgreSQL extension was not found, the DB handler will not be initialized.', 'eZPostgreSQLDB'); return; } eZDebug::createAccumulatorGroup('postgresql_total', 'Postgresql Total'); $ini = eZINI::instance(); $server = $this->Server; $port = $this->Port; $db = $this->DB; $user = $this->User; $password = $this->Password; $connectString = self::connectString($this->Server, $this->Port, $this->DB, $this->User, $this->Password); if ($ini->variable("DatabaseSettings", "UsePersistentConnection") == "enabled" && function_exists("pg_pconnect")) { eZDebugSetting::writeDebug('kernel-db-postgresql', $ini->variable("DatabaseSettings", "UsePersistentConnection"), "using persistent connection"); // avoid automatic SQL errors $oldHandling = eZDebug::setHandleType(eZDebug::HANDLE_EXCEPTION); eZDebug::accumulatorStart('postgresql_connection', 'postgresql_total', 'Database connection'); try { $this->DBConnection = pg_pconnect($connectString); } catch (ErrorException $e) { } eZDebug::accumulatorStop('postgresql_connection'); eZDebug::setHandleType($oldHandling); $maxAttempts = $this->connectRetryCount(); $waitTime = $this->connectRetryWaitTime(); $numAttempts = 1; while ($this->DBConnection == false and $numAttempts <= $maxAttempts) { sleep($waitTime); $oldHandling = eZDebug::setHandleType(eZDebug::HANDLE_EXCEPTION); eZDebug::accumulatorStart('postgresql_connection', 'postgresql_total', 'Database connection'); try { $this->DBConnection = pg_pconnect($connectString); } catch (ErrorException $e) { } eZDebug::accumulatorStop('postgresql_connection'); eZDebug::setHandleType($oldHandling); $numAttempts++; } if ($this->DBConnection) { $this->IsConnected = true; } else { throw new eZDBNoConnectionException($server, $this->ErrorMessage, $this->ErrorNumber); } } else { if (function_exists("pg_connect")) { eZDebugSetting::writeDebug('kernel-db-postgresql', "using real connection", "using real connection"); $oldHandling = eZDebug::setHandleType(eZDebug::HANDLE_EXCEPTION); eZDebug::accumulatorStart('postgresql_connection', 'postgresql_total', 'Database connection'); try { $this->DBConnection = pg_connect($connectString); } catch (ErrorException $e) { } eZDebug::accumulatorStop('postgresql_connection'); eZDebug::setHandleType($oldHandling); $maxAttempts = $this->connectRetryCount(); $waitTime = $this->connectRetryWaitTime(); $numAttempts = 1; while ($this->DBConnection == false and $numAttempts <= $maxAttempts) { sleep($waitTime); $oldHandling = eZDebug::setHandleType(eZDebug::HANDLE_EXCEPTION); eZDebug::accumulatorStart('postgresql_connection', 'postgresql_total', 'Database connection'); try { $this->DBConnection = pg_connect($connectString); } catch (ErrorException $e) { } eZDebug::accumulatorStop('postgresql_connection'); eZDebug::setHandleType($oldHandling); $numAttempts++; } if ($this->DBConnection) { $this->IsConnected = true; } else { $this->setError(); throw new eZDBNoConnectionException($server, $this->ErrorMessage, $this->ErrorNumber); } } else { $this->IsConnected = false; eZDebug::writeError("PostgreSQL support not compiled into PHP, contact your system administrator", "eZPostgreSQLDB"); } } }
function setClusterFrontendUrlData(array $clusterDomains, eZDBInterface $db, eZCLI $cli, $dumpSql) { $db->beginQuery(); foreach ($clusterDomains as $clusterIdentifier => $url) { $query = sprintf("UPDATE bo_cluster SET frontend_url = '%s' WHERE identifier='%s';", $url, $clusterIdentifier); if ($dumpSql) { $cli->notice($query); continue; } $cli->notice("Setting frontend_url to {$url} for cluster {$clusterIdentifier}"); $db->query($query); } return $db->commitQuery(); }
function __construct($parameters) { parent::__construct($parameters); }