Exemplo n.º 1
0
 /**
  * @return int
  */
 public static function lastInsertId()
 {
     return (int) self::$conn->lastInsertId();
 }
Exemplo n.º 2
0
}
// timezones are fun
date_default_timezone_set('America/Phoenix');
// configure the db connections holder
$db = new Aura\Sql\ConnectionLocator();
$db->setDefault(function () use($config) {
    $connection = $config->database->slave;
    return new Aura\Sql\ExtendedPdo("mysql:host={$connection->host}", $connection->user, $connection->password);
});
$db->setWrite('master', function () use($config) {
    $connection = $config->database->master;
    return new Aura\Sql\ExtendedPdo("mysql:host={$connection->host}", $connection->user, $connection->password);
});
$db->setRead('slave', function () use($config) {
    $connection = $config->database->slave;
    $pdo = new Aura\Sql\ExtendedPdo("mysql:host={$connection->host}", $connection->user, $connection->password);
    $profiler = new Aura\Sql\Profiler();
    $profiler->setActive(true);
    $pdo->setProfiler($profiler);
    return $pdo;
});
// setup logger
$logName = $_SERVER['PHP_SELF'];
$logName = explode('/', $logName);
$logName = end($logName);
$logName = explode('.', $logName);
$logName = current($logName);
$logPath = __DIR__ . "/logs/{$logName}.log";
$streamHandler = new Monolog\Handler\StreamHandler($logPath, Monolog\Logger::INFO);
$logger = new Monolog\Logger('script');
$logger->pushHandler($streamHandler);
Exemplo n.º 3
0
<?php

$startTime = microtime(true);
require_once __DIR__ . '/../bootstrap.php';
$commentDBConfig = $config->database->comment;
$commentDB = new Aura\Sql\ExtendedPdo("mysql:host={$commentDBConfig->host}", $commentDBConfig->user, $commentDBConfig->password);
$lastBatchLimit = $commentDB->fetchValue("\n    SELECT `comment`.`id`\n    FROM `comment_service`.`comment`\n    ORDER BY `id` DESC\n    LIMIT 1");
if (!$lastBatchLimit) {
    $lastBatchLimit = 0;
}
$opts = getopt('s:');
$limit = isset($opts['s']) && !empty($opts['s']) ? $opts['s'] : 100;
$commentBatch = $db->getRead()->fetchAll("\n    SELECT\n        `comment_meta`.`id`,\n        `comment`.`body`,\n        `comment`.`body_format`,\n        `commenter`.`name`,\n        `commenter`.`email`,\n        `commenter`.`url`,\n        `commenter`.`trusted`,\n        `comment_page`.`site`,\n        `comment_page`.`path`,\n        `comment_meta`.`reply`,\n        `comment_meta`.`notify`,\n        `comment_meta`.`date`,\n        `comment_meta`.`display`\n    FROM `jpemeric_comment`.`comment_meta`\n    INNER JOIN `jpemeric_comment`.`comment` ON `comment`.`id` = `comment_meta`.`comment`\n    INNER JOIN `jpemeric_comment`.`commenter` ON `commenter`.`id` = `comment_meta`.`commenter`\n    INNER JOIN `jpemeric_comment`.`comment_page` ON `comment_page`.`id` = `comment_meta`.`comment_page`\n    WHERE `comment_meta`.`id` > :last_batch_limit\n    ORDER BY `id` ASC LIMIT {$limit}", ['last_batch_limit' => $lastBatchLimit]);
$commentCount = count($commentBatch);
if ($commentCount < 1) {
    $logger->addInfo("Found no new comments to import, exiting early");
    exit;
}
$logger->addInfo("Found {$commentCount} comments to import, starting from ID: {$lastBatchLimit}.");
foreach ($commentBatch as $comment) {
    $query = "\n        SELECT `id` FROM `comment_service`.`commenter`\n        WHERE `name` = :name AND `email` = :email AND `website` = :website\n        LIMIT 1";
    $bindings = ['name' => $comment['name'], 'email' => $comment['email'], 'website' => $comment['url']];
    $commenterId = $commentDB->fetchValue($query, $bindings);
    if (!$commenterId) {
        $query = "\n            INSERT INTO `comment_service`.`commenter` (`name`, `email`, `website`, `is_trusted`)\n            VALUES (:name, :email, :website, :is_trusted)";
        $bindings = ['name' => $comment['name'], 'email' => $comment['email'], 'website' => $comment['url'], 'is_trusted' => $comment['trusted']];
        if (!$commentDB->perform($query, $bindings)) {
            $logger->addError('Could not insert commenter - exiting out');
            exit;
        }
        $commenterId = $commentDB->lastInsertId();