/** * @param AbstractDmlQuery $crudObj */ public static function crud(AbstractDmlQuery $crudObj) { self::$conn->perform($crudObj->getStatement(), $crudObj->getBindValues()); }
$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(); } $query = "\n INSERT INTO `comment_service`.`comment_body` (`body`)\n VALUES (:body)"; $bindings = ['body' => $comment['body']]; if (!$commentDB->perform($query, $bindings)) { $logger->addError('Could not insert comment_body - exiting out'); exit; } $bodyId = $commentDB->lastInsertId(); $domain = $comment['site'] == 2 ? 'blog.jacobemerick.com' : 'waterfallsofthekeweenaw.com'; $query = "\n SELECT `id` FROM `comment_service`.`comment_domain`\n WHERE `domain` = :domain LIMIT 1"; $bindings = ['domain' => $domain];