Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function tearDown()
 {
     $this->connection->execute('SET FOREIGN_KEY_CHECKS = 0');
     foreach ($this->connection->getTableNames() as $table_name) {
         $this->connection->dropTable($table_name);
     }
     $this->connection->execute('SET FOREIGN_KEY_CHECKS = 1');
     $this->connection->disconnect();
     parent::tearDown();
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function commitDispatchedJobIds()
 {
     if ($queue_id = $this->getQueueId()) {
         if (!empty($this->dispatched_job_ids)) {
             $this->connection->transact(function () use($queue_id) {
                 $this->connection->execute('UPDATE `' . MySqlQueue::BATCHES_TABLE_NAME . '` SET `jobs_count` = `jobs_count` + ? WHERE `id` = ?', count($this->dispatched_job_ids), $queue_id);
             });
         }
     } else {
         throw new RuntimeException("Can't commit dispatched job ID-s in an unsaved batch");
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function createBatch(DispatcherInterface &$dispatcher, $name)
 {
     if ($name) {
         $this->connection->execute('INSERT INTO `' . self::BATCHES_TABLE_NAME . '` (`name`, `created_at`) VALUES (?, UTC_TIMESTAMP())', $name);
         return new MySqlBatch($dispatcher, $this->connection, $this->connection->lastInsertId(), $name);
     } else {
         throw new InvalidArgumentException('Batch name is required');
     }
 }
 /**
  * Insert rows that are already loaded.
  */
 public function flush()
 {
     if ($this->is_done) {
         throw new RuntimeException('This batch insert is already done');
     }
     $count_rows = count($this->rows);
     if ($count_rows > 0) {
         $this->connection->execute($this->sql_foundation . implode(', ', $this->rows));
         $this->rows = [];
         $this->total += $count_rows;
     }
 }
Ejemplo n.º 5
0
 /**
  * @param string $table_name
  * @param string $prefixed_table_name
  */
 private function createConversionRateTriggers(string $table_name, string $prefixed_table_name)
 {
     if ($table_name == 'daily_conversions') {
         $insert_trigger = 'daily_trial_conversion_rate_on_insert';
         $update_trigger = 'daily_trial_conversion_rate_on_update';
     } else {
         $insert_trigger = 'monthly_trial_conversion_rate_on_insert';
         $update_trigger = 'monthly_trial_conversion_rate_on_update';
     }
     $this->connection->execute("DROP TRIGGER IF EXISTS `{$insert_trigger}`");
     $this->connection->execute("CREATE TRIGGER `{$insert_trigger}` BEFORE INSERT ON `{$prefixed_table_name}` FOR EACH ROW\n            BEGIN\n                IF NEW.visits > '0' AND NEW.trials > '0' THEN\n                    SET NEW.to_trial_rate = NEW.trials / NEW.visits * 100;\n                ELSE\n                    SET NEW.to_trial_rate = '0';\n                END IF;\n\n                IF NEW.visits > '0' AND NEW.conversions > '0' THEN\n                    SET NEW.to_paid_rate = NEW.conversions / NEW.visits * 100;\n                ELSE\n                    SET NEW.to_paid_rate = '0';\n                END IF;\n            END");
     $this->connection->execute("DROP TRIGGER IF EXISTS `{$update_trigger}`");
     $this->connection->execute("CREATE TRIGGER `{$update_trigger}` BEFORE UPDATE ON `{$prefixed_table_name}` FOR EACH ROW\n            BEGIN\n                IF NEW.visits != OLD.visits OR NEW.trials != OLD.trials OR NEW.conversions != OLD.conversions THEN\n                    IF NEW.visits > '0' AND NEW.trials > '0' THEN\n                        SET NEW.to_trial_rate = NEW.trials / NEW.visits * 100;\n                    ELSE\n                        SET NEW.to_trial_rate = '0';\n                    END IF;\n\n                    IF NEW.visits > '0' AND NEW.conversions > '0' THEN\n                        SET NEW.to_paid_rate = NEW.conversions / NEW.visits * 100;\n                    ELSE\n                        SET NEW.to_paid_rate = '0';\n                    END IF;\n                END IF;\n            END");
 }
Ejemplo n.º 6
0
 /**
  * Return name of the table where we store info about executed migrations.
  *
  * @return string
  */
 public function getTableName()
 {
     if ($this->table_exists === null && !in_array($this->table_name, $this->connection->getTableNames())) {
         $this->connection->execute('CREATE TABLE ' . $this->connection->escapeTableName($this->table_name) . ' (
             `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
             `migration` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
             `executed_at` datetime NOT NULL,
             PRIMARY KEY (`id`),
             UNIQUE KEY `migration` (`migration`),
             KEY `executed_on` (`executed_at`)
         ) ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;');
         $this->table_exists = true;
     }
     return $this->table_name;
 }
Ejemplo n.º 7
0
 /**
  * @param  PromiseInterface $promise
  * @return bool
  */
 public function reject(PromiseInterface $promise)
 {
     if ($this->isSettled($promise)) {
         throw new \LogicException("Settled promises can't be rejected");
     }
     $this->connection->execute('UPDATE ' . self::PROMISES_TABLE_NAME . ' SET `settlement` = ?, `settled_at` = UTC_TIMESTAMP() WHERE `signature` = ?', PromiseInterface::REJECTED, $promise->getSignature());
     if ($this->connection->affectedRows()) {
         if ($this->log) {
             $this->log->info('Promise {promise_id} rejected', ['promise_id' => $promise->getSignature()]);
         }
     } else {
         if ($this->log) {
             $this->log->error('Promise {promise_id} not found', ['promise_id' => $promise->getSignature()]);
         }
         throw new InvalidArgumentException("Promise '{$promise->getSignature()}' not found");
     }
 }