本文整理汇总了PHP中eZDB::setInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP eZDB::setInstance方法的具体用法?PHP eZDB::setInstance怎么用?PHP eZDB::setInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZDB
的用法示例。
在下文中一共展示了eZDB::setInstance方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Sets up the database enviroment
*/
protected function setUp()
{
if (ezpTestRunner::dbPerTest()) {
$dsn = ezpTestRunner::dsn();
$this->sharedFixture = ezpTestDatabaseHelper::create($dsn);
if ($this->insertDefaultData === true) {
ezpTestDatabaseHelper::insertDefaultData($this->sharedFixture);
}
if (count($this->sqlFiles > 0)) {
ezpTestDatabaseHelper::insertSqlData($this->sharedFixture, $this->sqlFiles);
}
}
eZDB::setInstance($this->sharedFixture);
}
示例2: pcntl_fork
}
for ($i = 0; $i < $optConcurrencyLevel; $i++) {
$pid = pcntl_fork();
// Problem launching the job
if ($pid == -1) {
error_log('Could not launch new job, exiting');
} else {
if ($pid > 1) {
$currentJobs[] = $pid;
} else {
$exitStatus = 0;
//Error code if you need to or whatever
$myPid = getmypid();
// No need if the DB ain't initialized before forking
$db = eZDB::instance(false, false, true);
eZDB::setInstance($db);
// suppress error output due to fatal DB errors
// exceptions from the DB layer would allow for better information output
fclose(STDERR);
$object = new ezpObject($optContentClass, $optParentNode);
$object->title = "Wait Timeout Test, pid {$myPid}\n";
if ($optGenerateContent === true) {
$object->body = file_get_contents('xmltextsource.txt');
}
$object->publish();
eZExecution::cleanExit();
}
}
}
if ($script->verboseOutputLevel() > 0) {
$cli->output("Main process: waiting for children...");
示例3: initializePackage
function initializePackage($siteType, &$accessMap, $charset, &$extraLanguageCodes, &$allLanguages, &$primaryLanguage, &$admin, &$resultArray)
{
// Time limit #3:
// We set the time limit to 5 minutes to ensure we have enough time
// to initialize the site. However we only set if the current limit
// is too small
$maxTime = ini_get('max_execution_time');
if ($maxTime != 0 and $maxTime < 5 * 60) {
@set_time_limit(5 * 60);
}
switch ($siteType['access_type']) {
case 'port':
$userSiteaccessName = $siteType['identifier'] . '_' . 'user';
$adminSiteaccessName = $siteType['identifier'] . '_' . 'admin';
$accessMap['port'][$siteType['access_type_value']] = $userSiteaccessName;
$accessMap['port'][$siteType['admin_access_type_value']] = $adminSiteaccessName;
break;
case 'hostname':
$userSiteaccessName = $siteType['identifier'] . '_' . 'user';
$adminSiteaccessName = $siteType['identifier'] . '_' . 'admin';
$accessMap['hostname'][$siteType['access_type_value']] = $userSiteaccessName;
$accessMap['hostname'][$siteType['admin_access_type_value']] = $adminSiteaccessName;
break;
case 'url':
default:
$userSiteaccessName = $siteType['access_type_value'];
$adminSiteaccessName = $siteType['admin_access_type_value'];
$accessMap['url'][$siteType['access_type_value']] = $userSiteaccessName;
$accessMap['url'][$siteType['admin_access_type_value']] = $adminSiteaccessName;
break;
}
$accessMap['accesses'][] = $userSiteaccessName;
$accessMap['accesses'][] = $adminSiteaccessName;
$accessMap['sites'][] = $userSiteaccessName;
$userDesignName = $siteType['identifier'];
$languageObjects = $allLanguages;
$databaseMap = eZSetupDatabaseMap();
$databaseInfo = $this->PersistenceList['database_info'];
$databaseInfo['info'] = $databaseMap[$databaseInfo['type']];
$dbServer = $databaseInfo['server'];
$dbPort = $databaseInfo['port'];
// $dbName = $databaseInfo['dbname'];
$dbSocket = $databaseInfo['socket'];
$dbUser = $databaseInfo['user'];
$dbPwd = $databaseInfo['password'];
$dbCharset = $charset;
$dbDriver = $databaseInfo['info']['driver'];
$dbName = $siteType['database'];
$dbParameters = array('server' => $dbServer, 'port' => $dbPort, 'user' => $dbUser, 'password' => $dbPwd, 'socket' => $dbSocket, 'database' => $dbName, 'charset' => $dbCharset);
$db = eZDB::instance($dbDriver, $dbParameters, true);
if (!$db->isConnected()) {
$resultArray['errors'][] = array('code' => 'EZSW-005', 'text' => "Failed connecting to database {$dbName}\n" . $db->errorMessage());
return false;
}
eZDB::setInstance($db);
$result = true;
// Initialize the database by inserting schema and data
if (!isset($siteType['existing_database'])) {
$siteType['existing_database'] = false;
}
if ($siteType['existing_database'] == eZStepInstaller::DB_DATA_REMOVE) {
eZDBTool::cleanup($db);
}
if ($siteType['existing_database'] != eZStepInstaller::DB_DATA_KEEP) {
$result = true;
$schemaArray = eZDbSchema::read('share/db_schema.dba', true);
if (!$schemaArray) {
$resultArray['errors'][] = array('code' => 'EZSW-001', 'message' => "Failed loading database schema file share/db_schema.dba");
$result = false;
}
if ($result) {
$result = true;
$dataArray = eZDbSchema::read('share/db_data.dba', true);
if (!$dataArray) {
$resultArray['errors'][] = array('code' => 'EZSW-002', 'text' => "Failed loading database data file share/db_data.dba");
$result = false;
}
if ($result) {
$schemaArray = array_merge($schemaArray, $dataArray);
$schemaArray['type'] = strtolower($db->databaseName());
$schemaArray['instance'] = $db;
$result = true;
$dbSchema = eZDbSchema::instance($schemaArray);
if (!$dbSchema) {
$resultArray['errors'][] = array('code' => 'EZSW-003', 'text' => "Failed loading " . $db->databaseName() . " schema handler");
$result = false;
}
if ($result) {
$result = true;
// This will insert the schema, then the data and
// run any sequence value correction SQL if required
$params = array('schema' => true, 'data' => true);
if ($db->databaseName() == 'mysql') {
$engines = $db->arrayQuery('SHOW ENGINES');
foreach ($engines as $engine) {
if ($engine['Engine'] == 'InnoDB' && in_array($engine['Support'], array('YES', 'DEFAULT'))) {
$params['table_type'] = 'innodb';
break;
}
}
//.........这里部分代码省略.........
示例4: initializeDB
/**
* Create custom DB connection if DB options provided
*/
protected function initializeDB()
{
$dbUser = $this->Options['db-user'] ? $this->Options['db-user'] : false;
$dbPassword = $this->Options['db-password'] ? $this->Options['db-password'] : false;
$dbHost = $this->Options['db-host'] ? $this->Options['db-host'] : false;
$dbName = $this->Options['db-database'] ? $this->Options['db-database'] : false;
$dbImpl = $this->Options['db-driver'] ? $this->Options['db-driver'] : false;
$showSQL = $this->Options['sql'] ? true : false;
$db = eZDB::instance();
if ($dbHost or $dbName or $dbUser or $dbImpl) {
$params = array();
if ($dbHost !== false) {
$params['server'] = $dbHost;
}
if ($dbUser !== false) {
$params['user'] = $dbUser;
$params['password'] = '';
}
if ($dbPassword !== false) {
$params['password'] = $dbPassword;
}
if ($dbName !== false) {
$params['database'] = $dbName;
}
$db = eZDB::instance($dbImpl, $params, true);
eZDB::setInstance($db);
}
$db->setIsSQLOutputEnabled($showSQL);
}
示例5: publish
/**
* Starts the publishing process for the linked version. After publishing,
* the child process is terminated.
*
* @return false|int false if the fork fails, the pid of the child process
* after the fork
*/
public function publish()
{
$contentObjectId = $this->version()->attribute('contentobject_id');
$contentObjectVersion = $this->version()->attribute('version');
// $processObject = ezpContentPublishingProcess::fetchByContentObjectVersion( $contentObjectId, $contentObjectVersion );
$this->setStatus(self::STATUS_WORKING, true, "beginning publishing");
// prepare the cluster file handler for the fork
eZClusterFileHandler::preFork();
$pid = pcntl_fork();
// force the DB connection closed
$db = eZDB::instance();
$db->close();
$db = null;
eZDB::setInstance(null);
// Force the new stack DB connection closed as well
try {
$kernel = ezpKernel::instance();
if ($kernel->hasServiceContainer()) {
$serviceContainer = $kernel->getServiceContainer();
$dbHandler = $serviceContainer->get('ezpublish.connection');
$factory = $serviceContainer->get('ezpublish.api.storage_engine.legacy.dbhandler.factory');
$dbHandler->setDbHandler($factory->buildLegacyDbHandler()->getDbHandler());
}
} catch (LogicException $e) {
// we just ignore this, since it means that we are running in a pure legacy context
}
// Force the cluster DB connection closed if the cluster handler is DB based
$cluster = eZClusterFileHandler::instance();
// error, cancel
if ($pid == -1) {
$this->setStatus(self::STATUS_PENDING, true, "pcntl_fork() failed");
return false;
} else {
if ($pid) {
return $pid;
}
}
// child process
try {
$myPid = getmypid();
pcntl_signal(SIGCHLD, SIG_IGN);
$this->setAttribute('pid', $myPid);
$this->setAttribute('started', time());
$this->store(array('pid', 'started'));
// login the version's creator to make sure publishing happens as if ran synchronously
$creatorId = $this->version()->attribute('creator_id');
$creator = eZUser::fetch($creatorId);
eZUser::setCurrentlyLoggedInUser($creator, $creatorId);
unset($creator, $creatorId);
$operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectId, 'version' => $contentObjectVersion));
// Statuses other than CONTINUE require special handling
if ($operationResult['status'] != eZModuleOperationInfo::STATUS_CONTINUE) {
if ($operationResult['status'] == eZModuleOperationInfo::STATUS_HALTED) {
// deferred to crontab
if (strpos($operationResult['result']['content'], 'Deffered to cron') !== false) {
$processStatus = self::STATUS_DEFERRED;
} else {
$processStatus = self::STATUS_UNKNOWN;
}
} else {
$processStatus = self::STATUS_UNKNOWN;
}
} else {
$processStatus = self::STATUS_FINISHED;
}
// mark the process as completed
$this->setAttribute('pid', 0);
$this->setStatus($processStatus, false, "publishing operation finished");
$this->setAttribute('finished', time());
$this->store(array('status', 'finished', 'pid'));
// Call the postProcessing hook
ezpContentPublishingQueue::signals()->emit('postHandling', $contentObjectId, $contentObjectVersion, $processStatus);
} catch (eZDBException $e) {
$this->reset("database error: " . $e->getMessage());
}
// generate static cache
$ini = eZINI::instance();
if ($ini->variable('ContentSettings', 'StaticCache') == 'enabled') {
$staticCacheHandlerClassName = $ini->variable('ContentSettings', 'StaticCacheHandler');
$staticCacheHandlerClassName::executeActions();
}
eZScript::instance()->shutdown();
exit;
}
示例6: setCurrentSite
/**
* Sets the current site.
*
* From eZ Publish.
*
* @param string $site Eg. 'plain_site_user'
* @todo remove or move in another class?
*/
public function setCurrentSite($site)
{
eZWebDAVContentBackend::appendLogEntry(__FUNCTION__ . '1:' . $site);
$access = array('name' => $site, 'type' => eZSiteAccess::TYPE_STATIC);
$access = eZSiteAccess::change($access);
eZWebDAVContentBackend::appendLogEntry(__FUNCTION__ . '2:' . $site);
eZDebugSetting::writeDebug('kernel-siteaccess', $access, 'current siteaccess');
// Clear/flush global database instance.
$nullVar = null;
eZDB::setInstance($nullVar);
}
示例7: setCurrentSite
function setCurrentSite( $site )
{
$access = array( 'name' => $site,
'type' => eZSiteAccess::TYPE_STATIC );
$access = eZSiteAccess::change( $access );
eZDebugSetting::writeDebug( 'kernel-siteaccess', $access, 'current siteaccess' );
// Clear/flush global database instance.
$nullVar = null;
eZDB::setInstance( $nullVar );
}
示例8: childSignalHandler
/**
* Child process signal handler
*/
public function childSignalHandler($signo, $pid = null, $status = null)
{
// If no pid is provided, that means we're getting the signal from the system. Let's figure out
// which child process ended
if ($pid === null) {
$pid = pcntl_waitpid(-1, $status, WNOHANG);
}
//Make sure we get all of the exited children
while ($pid > 0) {
if ($pid && isset($this->currentJobs[$pid])) {
$exitCode = pcntl_wexitstatus($status);
if ($exitCode != 0) {
$this->out->write("Process #{$pid} of object version #" . $this->currentJobs[$pid]->attribute('ezcontentobject_version_id') . " exited with status {$exitCode}");
// this is required as the MySQL connection might be closed anytime by a fork
// this method is asynchronous, and might be triggered by any signal
// the only way is to use a dedicated DB connection, and close it afterwards
eZDB::setInstance(eZDB::instance(false, false, true));
$this->currentJobs[$pid]->reset();
eZDB::instance()->close();
eZDB::setInstance(null);
}
unset($this->currentJobs[$pid]);
} elseif ($pid) {
$this->signalQueue[$pid] = $status;
}
$pid = pcntl_waitpid(-1, $status, WNOHANG);
}
return true;
}
示例9: publish
/**
* Starts the publishing process for the linked version. After publishing,
* the child process is terminated.
*
* @return false|int false if the fork fails, the pid of the child process
* after the fork
*/
public function publish()
{
$contentObjectId = $this->version()->attribute('contentobject_id');
$contentObjectVersion = $this->version()->attribute('version');
// $processObject = ezpContentPublishingProcess::fetchByContentObjectVersion( $contentObjectId, $contentObjectVersion );
$this->setAttribute('status', self::STATUS_WORKING);
$this->store(array('status'));
// prepare the cluster file handler for the fork
eZClusterFileHandler::preFork();
$pid = pcntl_fork();
// force the DB connection closed
$db = eZDB::instance();
$db->close();
$db = null;
eZDB::setInstance(null);
// Force the cluster DB connection closed if the cluster handler is DB based
$cluster = eZClusterFileHandler::instance();
// error, cancel
if ($pid == -1) {
$this->setAttribute('status', self::STATUS_PENDING);
$this->store(array('status'));
return false;
} else {
if ($pid) {
return $pid;
}
}
// child process
try {
$myPid = getmypid();
pcntl_signal(SIGCHLD, SIG_IGN);
$this->setAttribute('pid', $myPid);
$this->setAttribute('started', time());
$this->store(array('pid', 'started'));
// login the version's creator to make sure publishing happens as if ran synchronously
$creatorId = $this->version()->attribute('creator_id');
$creator = eZUser::fetch($creatorId);
eZUser::setCurrentlyLoggedInUser($creator, $creatorId);
unset($creator, $creatorId);
$operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectId, 'version' => $contentObjectVersion));
// Statuses other than CONTINUE require special handling
if ($operationResult['status'] != eZModuleOperationInfo::STATUS_CONTINUE) {
if ($operationResult['status'] == eZModuleOperationInfo::STATUS_HALTED) {
// deferred to crontab
if (strpos($operationResult['result']['content'], 'Deffered to cron') !== false) {
$processStatus = self::STATUS_DEFERRED;
} else {
$processStatus = self::STATUS_UNKNOWN;
}
} else {
$processStatus = self::STATUS_UNKNOWN;
}
} else {
$processStatus = self::STATUS_FINISHED;
}
// mark the process as completed
$this->setAttribute('pid', 0);
$this->setAttribute('status', $processStatus);
$this->setAttribute('finished', time());
$this->store(array('status', 'finished', 'pid'));
// Call the postProcessing hook
ezpContentPublishingQueue::signals()->emit('postHandling', $contentObjectId, $contentObjectVersion, $processStatus);
} catch (eZDBException $e) {
$this->reset();
}
eZScript::instance()->shutdown();
exit;
}
示例10: initializeDB
/**
* Create custom DB connection if DB options provided
*/
protected function initializeDB()
{
$dbUser = $this->Options['db-user'] ? $this->Options['db-user'] : false;
$dbPassword = $this->Options['db-password'] ? $this->Options['db-password'] : false;
$dbHost = $this->Options['db-host'] ? $this->Options['db-host'] : false;
$dbName = $this->Options['db-database'] ? $this->Options['db-database'] : false;
$dbImpl = $this->Options['db-driver'] ? $this->Options['db-driver'] : false;
$showSQL = $this->Options['sql'] ? true : false;
// Forcing creation of new instance to avoid mysql wait_timeout to kill
// the connection before it's done
$db = eZDB::instance(false, false, true);
if ($dbHost or $dbName or $dbUser or $dbImpl) {
$params = array();
if ($dbHost !== false) {
$params['server'] = $dbHost;
}
if ($dbUser !== false) {
$params['user'] = $dbUser;
$params['password'] = '';
}
if ($dbPassword !== false) {
$params['password'] = $dbPassword;
}
if ($dbName !== false) {
$params['database'] = $dbName;
}
$db = eZDB::instance($dbImpl, $params, true);
eZDB::setInstance($db);
}
$db->setIsSQLOutputEnabled($showSQL);
}
示例11: resetDatabaseHandler
/**
* Resets the database handler back to default
*
* @return eZDB Instance of eZDB
*/
public function resetDatabaseHandler()
{
if (!$this->DefaultDB->isConnected()) {
return false;
}
eZDB::setInstance($this->DefaultDB);
return $this->DefaultDB;
}
示例12: call
/**
* call the WS and log if an error occured
*
* @param string $commandName
* @param array $params
* @throws Exception
* @throws ezcLogWriterException
* @return array
*/
public static function call($commandName, $params)
{
// $params = DbTool::escapeRecursiveArray($params);
$result = '';
WSHelper::instance()->logger->log(var_export($params, true), ezcLog::INFO );
WSHelper::instance()->logger->log( str_pad('', 77, '*'), ezcLog::INFO);
try
{
$command = WSHelper::instance()->client->getCommand($commandName, $params);
$command->prepare();
$httpRequest = $command->getRequest();
$httpRequest->setHeader('Content-Type','application/json');
$httpRequest->setHeader('Pragma', 'no-cache');
$httpRequest->setHeader('Content-cache', 'no-cache');
WSHelper::instance()->logger->log("[Guzzle - Request] ".$httpRequest, ezcLog::INFO);
eZDB::instance()->close(); // explicitely close the db connection to let it free in case of timeout
MMDB::resetInstance();
$httpResponse = $command->getResponse();
$forceDBOpen = eZDB::instance(false, false, true); // force connection reopen
eZDB::setInstance( $forceDBOpen );
WSHelper::instance()->logger->log("[Guzzle - Response] ".$httpResponse, ezcLog::INFO);
$result = $httpResponse->json();
// log error (header != 200 OK AND login fail)
if ( $httpResponse->isError()
|| ( (isset($result['Login']) && $result['Login'] == "no" ) ))
{
$logMessage = !empty($result['Msg']) ? $result['Msg'] : "Unkwown";
$logLevel = ezcLog::WARNING;
}
else
{
$logLevel = ezcLog::INFO;
if ( isset($result['Login']) && $result['Login'] == "yes") $logMessage = "Login success";
else $logMessage = $commandName . ' successful';
}
WSHelper::instance()->logger->log($logMessage, $logLevel );
return $result;
}
catch( Guzzle\Http\Exception\CurlException $e )
{
$curlError = self::getCurlError( $e->getMessage() );
$logMessage = "[Guzzle] CurlException #{$curlError['code']}: {$curlError['message']}";
WSHelper::instance()->logger->log($logMessage, ezcLog::ERROR);
self::logError($commandName, $params, $result, $logMessage);
return array(
'Data' => array(
'Status' => 'Error',
'ErrorCode' => 10,
'Msg' => "#{$curlError['code']}: {$curlError['message']}"
)
);
}
catch(Guzzle\Common\Exception\BadMethodCallException $e)
{
$logMessage = '[Guzzle] BadMethodCallException #'.$e->getCode().':'.$e->getMessage();
WSHelper::instance()->logger->log($logMessage, ezcLog::ERROR);
self::logError($commandName, $params, $result, $logMessage);
}
catch(Guzzle\Common\Exception\InvalidArgumentException $e)
{
$logMessage = '[Guzzle] InvalidArgumentException #'.$e->getCode().':'.$e->getMessage();
WSHelper::instance()->logger->log($logMessage, ezcLog::ERROR);
self::logError($commandName, $params, $result, $logMessage);
}
catch(Guzzle\Common\Exception\RuntimeException $e)
{
$logMessage = '[Guzzle] RuntimeException #'.$e->getCode().':'.$e->getMessage();
WSHelper::instance()->logger->log($logMessage, ezcLog::ERROR);
self::logError($commandName, $params, $result, $logMessage);
}
catch(Guzzle\Common\Exception\UnexpectedValueException $e)
{
$logMessage = '[Guzzle] UnexpectedValueException #'.$e->getCode().':'.$e->getMessage();
WSHelper::instance()->logger->log($logMessage, ezcLog::ERROR);
self::logError($commandName, $params, $result, $logMessage);
}
catch(Exception $e)
{
$logMessage = "[Exception] #".$e->getCode().':'.$e->getMessage();
WSHelper::instance()->logger->log($logMessage, ezcLog::ERROR);
self::logError($commandName, $params, $result, $logMessage);
}
return null;
}