本文整理汇总了PHP中Scalr::getDb方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr::getDb方法的具体用法?PHP Scalr::getDb怎么用?PHP Scalr::getDb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr
的用法示例。
在下文中一共展示了Scalr::getDb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __call
public function __call($method, $args)
{
// If observer enabled
if (!$this->Config || $this->Config->GetFieldByName("IsEnabled")->Value == 0) {
return;
}
$enabled = $this->Config->GetFieldByName("{$method}Notify");
if (!$enabled || $enabled->Value == 0) {
return;
}
$DB = \Scalr::getDb();
// Event name
$name = substr($method, 2);
// Event message
$message = $DB->GetOne("SELECT message FROM events WHERE event_id = ? LIMIT 1", array($args[0]->GetEventID()));
$farm_name = $DB->GetOne("SELECT name FROM farms WHERE id=? LIMIT 1", array($args[0]->GetFarmID()));
// Set subject
if (!$farm_name) {
$this->Mailer->setSubject("{$name} event notification (FarmID: {$args[0]->GetFarmID()})");
} else {
$this->Mailer->setSubject("{$name} event notification (FarmID: {$args[0]->GetFarmID()} FarmName: {$farm_name})");
}
// Set body
$this->Mailer->setMessage($message);
// Send mail
try {
$res = $this->Mailer->send();
} catch (\Exception $e) {
$res = false;
}
if (!$res) {
Logger::getLogger(__CLASS__)->info("Mail sent to '{$this->Config->GetFieldByName("EventMailTo")->Value}'. Result: {$res}");
}
}
示例2: StartThread
public function StartThread($farminfo)
{
$db = \Scalr::getDb();
$DBFarm = DBFarm::LoadByID($farminfo['id']);
foreach ($DBFarm->GetFarmRoles() as $DBFarmRole) {
foreach ($DBFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, SERVER_STATUS::PENDING, SERVER_STATUS::TROUBLESHOOTING)), array()) as $DBServer) {
$launchTime = strtotime($DBServer->dateAdded);
$lastCheckTime = (int) $DBServer->GetProperty(SERVER_PROPERTIES::STATISTICS_LAST_CHECK_TS);
if (!$lastCheckTime) {
$lastCheckTime = $launchTime;
}
$period = round((time() - $lastCheckTime) / 60);
$maxMinutes = date("j") * 24 * 60 - date("H") * 60;
if ($period > $maxMinutes) {
$period = $maxMinutes;
}
$serverType = $DBServer->GetFlavor();
if (!$serverType) {
continue;
}
$db->Execute("INSERT INTO servers_stats SET\n `usage` = ?,\n `instance_type` = ?,\n `env_id` = ?,\n `month` = ?,\n `year` = ?,\n `farm_id` = ?,\n `cloud_location` = ?\n ON DUPLICATE KEY UPDATE `usage` = `usage` + ?\n ", array($period, $serverType, $DBServer->envId, date("m"), date("Y"), $DBServer->farmId, $DBServer->GetCloudLocation(), $period));
$DBServer->SetProperty(SERVER_PROPERTIES::STATISTICS_LAST_CHECK_TS, time());
}
//for each items
}
}
示例3: enqueue
/**
* {@inheritdoc}
* @see \Scalr\System\Zmq\Cron\TaskInterface::enqueue()
*/
public function enqueue()
{
$queue = new ArrayObject([]);
$db = \Scalr::getDb();
$this->log('INFO', "Fetching farms...");
$farms = [];
$rs = $db->Execute("\n SELECT env_id, value FROM governance\n WHERE enabled = 1 AND name = ?\n ", [Scalr_Governance::GENERAL_LEASE]);
while ($env = $rs->FetchRow()) {
$env['value'] = json_decode($env['value'], true);
$period = 0;
if (is_array($env['value']['notifications'])) {
foreach ($env['value']['notifications'] as $notif) {
if ($notif['period'] > $period) {
$period = $notif['period'];
}
}
$dt = new DateTime();
$dt->add(new DateInterval('P' . $period . 'D'));
$fs = $db->GetAll("\n SELECT fs.farmid, f.status\n FROM farm_settings fs\n JOIN farms f ON f.id = fs.farmid\n WHERE fs.name = ? AND f.status = ? AND f.env_id = ? AND fs.value < ? AND fs.value != ''\n ", [Entity\FarmSetting::LEASE_TERMINATE_DATE, FARM_STATUS::RUNNING, $env['env_id'], $dt->format('Y-m-d H:i:s')]);
foreach ($fs as $f) {
if (!isset($farms[$f['farmid']])) {
$farms[$f['farmid']] = true;
$obj = new stdClass();
$obj->farmId = $f['farmid'];
$queue->append($obj);
}
}
}
}
$cnt = count($farms);
$this->log('INFO', "%d lease task%s %s found", $cnt, $cnt != 1 ? 's' : '', $cnt != 1 ? 'were' : 'was');
return $queue;
}
示例4: testDiff
/**
* @test
* @dataProvider providerDiffFiles
*/
public function testDiff(SplFileObject $source, SplFileObject $target, $testSourceSchema, $testTargetSchema)
{
$connection = \Scalr::getDb();
try {
if (!@$connection->Execute("SELECT 1;")) {
$this->markTestSkipped("No DB connection!");
}
} catch (Exception $e) {
$this->markTestSkipped("No DB connection!");
}
try {
$connection->Execute("SET FOREIGN_KEY_CHECKS=0;");
$this->createTestSchema($source, $connection, $testSourceSchema);
$this->createTestSchema($target, $connection, $testTargetSchema);
$diff = new Diff(new FileStream("ddl://localhost/{$testSourceSchema}"), new FileStream("ddl://localhost/{$testTargetSchema}"));
$statements = $diff->diff();
$connection->Execute("USE {$testTargetSchema};");
foreach ($statements as $statement) {
$connection->Execute($statement);
}
$diff = new Diff(new FileStream("ddl://localhost/{$testSourceSchema}"), new FileStream("ddl://localhost/{$testTargetSchema}"));
$statements = $diff->diff();
$this->assertEquals("", implode("\n", $statements));
} catch (ADODB_Exception $adoe) {
$this->markTestSkipped($adoe->getMessage());
} catch (Exception $e) {
$this->fail($e->getMessage($e->getMessage()));
}
$connection->Execute("DROP DATABASE IF EXISTS `{$testSourceSchema}`");
$connection->Execute("DROP DATABASE IF EXISTS `{$testTargetSchema}`");
}
示例5: __call
public function __call($method, $args)
{
// If observer enabled
if (!$this->Config || $this->Config->GetFieldByName("IsEnabled")->Value == 0) {
return;
}
$url = $this->Config->GetFieldByName("{$method}NotifyURL");
if (!$url || $url->Value == '') {
return;
}
$DB = \Scalr::getDb();
// Event message
$message = urlencode($DB->GetOne("SELECT message FROM events WHERE event_id = ? LIMIT 1", array($args[0]->GetEventID())));
$ch = @curl_init();
// set URL and other appropriate options
@curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
@curl_setopt($ch, CURLOPT_URL, $url->Value);
@curl_setopt($ch, CURLOPT_HEADER, false);
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, "event={$method}&message={$message}");
// grab URL and pass it to the browser
@curl_exec($ch);
$error = curl_error();
if ($error) {
Logger::getLogger(__CLASS__)->error($error);
}
// close cURL resource, and free up system resources
@curl_close($ch);
}
示例6: doJob
public static function doJob($job)
{
$db = \Scalr::getDb();
$messageSerializer = new Scalr_Messaging_XmlSerializer();
$message = $db->GetRow("SELECT server_id, message, id, handle_attempts FROM messages WHERE id=?", array($job->workload()));
try {
if ($message['handle_attempts'] >= 3) {
$db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::FAILED, $message['id']));
} else {
try {
$DBServer = DBServer::LoadByID($message['server_id']);
} catch (Exception $e) {
$db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::FAILED, $message['id']));
return;
}
if ($DBServer->status == SERVER_STATUS::RUNNING || $DBServer->status == SERVER_STATUS::INIT || $DBServer->status == SERVER_STATUS::IMPORTING || $DBServer->status == SERVER_STATUS::TEMPORARY || $DBServer->status == SERVER_STATUS::PENDING_TERMINATE) {
// Only 0.2-68 or greater version support this feature.
if ($DBServer->IsSupported("0.2-68")) {
$msg = $messageSerializer->unserialize($message['message']);
$DBServer->SendMessage($msg);
} else {
$db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::UNSUPPORTED, $message['id']));
}
} elseif (in_array($DBServer->status, array(SERVER_STATUS::TERMINATED, SERVER_STATUS::PENDING_TERMINATE))) {
$db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::FAILED, $message['id']));
}
}
} catch (Exception $e) {
//var_dump($e->getMessage());
}
}
示例7: __construct
/**
* Constructor
*
* @param unknown_type $queue_name
*/
public function __construct($queue_name)
{
$this->QueueName = $queue_name;
$this->DB = \Scalr::getDb();
$this->ReflectionTask = new ReflectionClass("Task");
$this->LastTaskID = 0;
}
示例8: __construct
function __construct($zohoCrm)
{
$this->zohoCrm = $zohoCrm;
$this->db = \Scalr::getDb();
$this->zohoMappings = new Scalr_Integration_ZohoCrm_CustomFields();
$this->logger = Logger::getLogger(__CLASS__);
}
示例9: activateOptions
/**
* Setup db connection.
* Based on defined options, this method connects to db defined in {@link $dsn}
* and creates a {@link $table} table if {@link $createTable} is true.
* @return boolean true if all ok.
*/
function activateOptions()
{
$this->db = \Scalr::getDb();
$this->layout = LoggerReflectionUtils::createObject('LoggerPatternLayoutScalr');
$this->layout->setConversionPattern($this->getSql());
$this->canAppend = true;
}
示例10: __construct
public function __construct($id = null)
{
$this->id = $id;
$this->container = \Scalr::getContainer();
$this->db = \Scalr::getDb();
$this->dbMessageKeyNotFound = get_class($this) . " " . $this->dbMessageKeyNotFound;
}
示例11: __construct
public function __construct($envId, $scope = Scalr_Scripting_GlobalVariables::SCOPE_ENVIRONMENT)
{
$this->crypto = new Scalr_Util_CryptoTool(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB, @mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB), @mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB));
$this->cryptoKey = @file_get_contents(APPPATH . "/etc/.cryptokey");
$this->envId = $envId;
$this->scope = $scope;
$this->db = \Scalr::getDb();
}
示例12: __construct
/**
* Recrypt
*
* @param string $scheme Database scheme
* @param CryptoTool $source Current encryption
* @param CryptoTool $target New encryption
* @param Console $console Console handler
*/
public function __construct($scheme, CryptoTool $source, CryptoTool $target, Console $console)
{
$this->db = \Scalr::getDb();
$this->scheme = $scheme;
$this->source = $source;
$this->target = $target;
$this->console = $console;
}
示例13: __construct
public function __construct()
{
$this->request = Scalr_UI_Request::getInstance();
$this->response = Scalr_UI_Response::getInstance();
$this->user = $this->request->getUser();
$this->environment = $this->request->getEnvironment();
$this->container = Scalr::getContainer();
$this->db = Scalr::getDb();
}
示例14: __construct
/**
* @param int $accountId
* @param int $envId
* @param string $scope
*/
public function __construct($accountId = 0, $envId = 0, $scope = Scalr_Scripting_GlobalVariables::SCOPE_SCALR)
{
$this->crypto = \Scalr::getContainer()->crypto;
$this->accountId = $accountId;
$this->envId = $envId;
$this->scope = $scope;
$this->listScopes = [self::SCOPE_SCALR, self::SCOPE_ACCOUNT, self::SCOPE_ENVIRONMENT, self::SCOPE_ROLE, self::SCOPE_FARM, self::SCOPE_FARMROLE, self::SCOPE_SERVER];
$this->db = \Scalr::getDb();
}
示例15: loadByVolumeId
/**
* @return DBEBSVolume
* @param string $volumeId
*/
public static function loadByVolumeId($volumeId)
{
$db = \Scalr::getDb();
$ebs_info = $db->GetRow("SELECT id FROM ec2_ebs WHERE volume_id = ? LIMIT 1", array($volumeId));
if (!$ebs_info) {
throw new Exception(sprintf(_("EBS volume ID#%s not found in database"), $volumeId));
}
return self::loadById($ebs_info['id']);
}