Permalink
Browse files

Finish type imports

  • Loading branch information...
jacobemerick committed Nov 25, 2017
1 parent ef7294c commit 14e33e46dde91f5dd8fc95b60f7e9fc820d96f05
Showing with 228 additions and 6 deletions.
  1. +228 −6 script/import-types.php
@@ -52,13 +52,235 @@
VALUES
(:id, :permalink, :datetime, :metadata, :created_at)";
$insertSth = $pdoNew->prepare($insertQuery);
foreach ($pdoOld->yieldAll($selectQuery) as $oldBlog) {
foreach ($pdoOld->yieldAll($selectQuery) as $row) {
$result = $insertSth->execute([
'id' => $oldBlog['id'],
'permalink' => $oldBlog['permalink'],
'datetime' => $oldBlog['datetime'],
'metadata' => $oldBlog['metadata'],
'created_at' => $oldBlog['created_at'],
'id' => $row['id'],
'permalink' => $row['permalink'],
'datetime' => $row['datetime'],
'metadata' => $row['metadata'],
'created_at' => $row['created_at'],
]);
if (!$result) {
throw new Exception($insertSth->errorInfo());
}
}
/**
* Blog Comments
*/
try {
$pdoNew->exec("TRUNCATE `blog_comment`");
} catch (Exception $e) {
throw new Exception($pdoNew->errorInfo());
}
$selectQuery = "
SELECT *
FROM `blog_comment`";
$insertQuery = "
INSERT INTO `blog_comment`
(`id`, `permalink`, `datetime`, `metadata`, `created_at`)
VALUES
(:id, :permalink, :datetime, :metadata, :created_at)";
$insertSth = $pdoNew->prepare($insertQuery);
foreach ($pdoOld->yieldAll($selectQuery) as $row) {
$result = $insertSth->execute([
'id' => $row['id'],
'permalink' => $row['permalink'],
'datetime' => $row['datetime'],
'metadata' => $row['metadata'],
'created_at' => $row['created_at'],
]);
if (!$result) {
throw new Exception($insertSth->errorInfo());
}
}
/**
* Book
*/
try {
$pdoNew->exec("TRUNCATE `book`");
} catch (Exception $e) {
throw new Exception($pdoNew->errorInfo());
}
$selectQuery = "
SELECT *
FROM `goodread`";
$insertQuery = "
INSERT INTO `book`
(`id`, `permalink`, `book_id`, `datetime`, `metadata`, `created_at`)
VALUES
(:id, :permalink, :book_id, :datetime, :metadata, :created_at)";
$insertSth = $pdoNew->prepare($insertQuery);
foreach ($pdoOld->yieldAll($selectQuery) as $row) {
$result = $insertSth->execute([
'id' => $row['id'],
'permalink' => $row['permalink'],
'book_id' => $row['book_id'],
'datetime' => $row['datetime'],
'metadata' => $row['metadata'],
'created_at' => $row['created_at'],
]);
if (!$result) {
throw new Exception($insertSth->errorInfo());
}
}
/**
* Code
*/
try {
$pdoNew->exec("TRUNCATE `code`");
} catch (Exception $e) {
throw new Exception($pdoNew->errorInfo());
}
$selectQuery = "
SELECT *
FROM `github`";
$insertQuery = "
INSERT INTO `code`
(`id`, `event_id`, `type`, `datetime`, `metadata`, `created_at`)
VALUES
(:id, :event_id, :type, :datetime, :metadata, :created_at)";
$insertSth = $pdoNew->prepare($insertQuery);
foreach ($pdoOld->yieldAll($selectQuery) as $row) {
$result = $insertSth->execute([
'id' => $row['id'],
'event_id' => $row['event_id'],
'type' => $row['type'],
'datetime' => $row['datetime'],
'metadata' => $row['metadata'],
'created_at' => $row['created_at'],
]);
if (!$result) {
throw new Exception($insertSth->errorInfo());
}
}
/**
* Distance
*/
try {
$pdoNew->exec("TRUNCATE `distance`");
} catch (Exception $e) {
throw new Exception($pdoNew->errorInfo());
}
$selectQuery = "
SELECT *
FROM `dailymile`";
$insertQuery = "
INSERT INTO `distance`
(`id`, `entry_id`, `type`, `datetime`, `metadata`, `created_at`)
VALUES
(:id, :entry_id, :type, :datetime, :metadata, :created_at)";
$insertSth = $pdoNew->prepare($insertQuery);
foreach ($pdoOld->yieldAll($selectQuery) as $row) {
$result = $insertSth->execute([
'id' => $row['id'],
'entry_id' => $row['entry_id'],
'type' => $row['type'],
'datetime' => $row['datetime'],
'metadata' => $row['metadata'],
'created_at' => $row['created_at'],
]);
if (!$result) {
throw new Exception($insertSth->errorInfo());
}
}
/**
* Distance
*/
try {
$pdoNew->exec("TRUNCATE `distance`");
} catch (Exception $e) {
throw new Exception($pdoNew->errorInfo());
}
$selectQuery = "
SELECT *
FROM `dailymile`";
$insertQuery = "
INSERT INTO `distance`
(`id`, `entry_id`, `type`, `datetime`, `metadata`, `created_at`)
VALUES
(:id, :entry_id, :type, :datetime, :metadata, :created_at)";
$insertSth = $pdoNew->prepare($insertQuery);
foreach ($pdoOld->yieldAll($selectQuery) as $row) {
$result = $insertSth->execute([
'id' => $row['id'],
'entry_id' => $row['entry_id'],
'type' => $row['type'],
'datetime' => $row['datetime'],
'metadata' => $row['metadata'],
'created_at' => $row['created_at'],
]);
if (!$result) {
throw new Exception($insertSth->errorInfo());
}
}
/**
* Twitter
*/
try {
$pdoNew->exec("TRUNCATE `twitter`");
} catch (Exception $e) {
throw new Exception($pdoNew->errorInfo());
}
$selectQuery = "
SELECT *
FROM `twitter`";
$insertQuery = "
INSERT INTO `twitter`
(`id`, `tweet_id`, `datetime`, `metadata`, `created_at`, `updated_at`)
VALUES
(:id, :tweet_id, :datetime, :metadata, :created_at, :updated_at)";
$insertSth = $pdoNew->prepare($insertQuery);
foreach ($pdoOld->yieldAll($selectQuery) as $row) {
$result = $insertSth->execute([
'id' => $row['id'],
'tweet_id' => $row['tweet_id'],
'datetime' => $row['datetime'],
'metadata' => $row['metadata'],
'created_at' => $row['created_at'],
'updated_at' => $row['updated_at'],
]);
if (!$result) {
throw new Exception($insertSth->errorInfo());
}
}
/**
* Video
*/
try {
$pdoNew->exec("TRUNCATE `video`");
} catch (Exception $e) {
throw new Exception($pdoNew->errorInfo());
}
$selectQuery = "
SELECT *
FROM `youtube`";
$insertQuery = "
INSERT INTO `video`
(`id`, `video_id`, `datetime`, `metadata`, `created_at`)
VALUES
(:id, :video_id, :datetime, :metadata, :created_at)";
$insertSth = $pdoNew->prepare($insertQuery);
foreach ($pdoOld->yieldAll($selectQuery) as $row) {
$result = $insertSth->execute([
'id' => $row['id'],
'video_id' => $row['video_id'],
'datetime' => $row['datetime'],
'metadata' => $row['metadata'],
'created_at' => $row['created_at'],
]);
if (!$result) {
throw new Exception($insertSth->errorInfo());

0 comments on commit 14e33e4

Please sign in to comment.