예제 #1
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();