flash.moe/public/dumplite/index.php
2022-02-05 03:39:41 +00:00

132 lines
9.3 KiB
PHP

<?php
require_once __DIR__ . '/../_v4/includes.php';
error_reporting(-1);
ini_set('display_errors', 'On');
$dbName = tempnam(sys_get_temp_dir(), 'v4d');
$sqlite = new SQLite3($dbName, SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
$sqlite->enableExceptions(true);
// tables
$sqlite->exec('CREATE TABLE "fm_blog_posts" ("post_id" INTEGER NOT NULL, "user_id" INTEGER DEFAULT NULL, "post_created" INTEGER NOT NULL, "post_published" INTEGER DEFAULT NULL, "post_updated" INTEGER DEFAULT NULL, "post_deleted" INTEGER DEFAULT NULL, "post_safe" INTEGER DEFAULT 0, "post_title" TEXT NOT NULL, "post_text" TEXT NOT NULL, "post_new_url" TEXT DEFAULT NULL);');
$sqlite->exec('CREATE TABLE "fm_blog_tags" ("tag_id" INTEGER NOT NULL, "tag_name" TEXT NOT NULL, "tag_slug" TEXT NOT NULL UNIQUE, "tag_description" TEXT, "tag_created" INTEGER NOT NULL, PRIMARY KEY("tag_id" AUTOINCREMENT));');
$sqlite->exec('CREATE TABLE "fm_blog_posts_tags" ("post_id" INTEGER NOT NULL, "tag_id" INTEGER NOT NULL, PRIMARY KEY("tag_id","post_id"), FOREIGN KEY("post_id") REFERENCES "fm_blog_posts"("post_id") ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY("post_id") REFERENCES "fm_blog_posts" ("post_id") ON UPDATE CASCADE ON DELETE CASCADE);');
$sqlite->exec('CREATE TABLE "fm_blog_wordpress" ("post_id" INTEGER NOT NULL, "wordpress_id" INTEGER NOT NULL UNIQUE, "wordpress_name" TEXT NOT NULL UNIQUE, FOREIGN KEY("post_id") REFERENCES "fm_blog_posts"("post_id") ON UPDATE CASCADE ON DELETE CASCADE, PRIMARY KEY("post_id"));');
$sqlite->exec('CREATE TABLE "fm_proglangs" ("language_id" INTEGER NOT NULL, "language_name" TEXT NOT NULL UNIQUE, "language_colour" INTEGER DEFAULT NULL, PRIMARY KEY("language_id" AUTOINCREMENT));');
$sqlite->exec('CREATE TABLE "fm_projects" ("project_id" INTEGER NOT NULL, "project_name" TEXT NOT NULL UNIQUE, "project_name_clean" TEXT DEFAULT NULL UNIQUE, "project_summary" TEXT DEFAULT NULL, "project_description" TEXT DEFAULT NULL, "project_order" INTEGER NOT NULL DEFAULT 0, "project_type" TEXT NOT NULL DEFAULT \'Project\', "project_featured" INTEGER NOT NULL, "project_colour" INTEGER DEFAULT NULL, "project_homepage" TEXT DEFAULT NULL, "project_repository" TEXT DEFAULT NULL, "project_forum" TEXT DEFAULT NULL, "project_created" INTEGER NOT NULL, "project_deleted" INTEGER DEFAULT NULL, "project_archived" INTEGER DEFAULT NULL, PRIMARY KEY("project_id" AUTOINCREMENT));');
$sqlite->exec('CREATE TABLE "fm_projects_proglangs" ("project_id" INTEGER NOT NULL, "language_id" INTEGER NOT NULL, "priority" INTEGER NOT NULL DEFAULT 0, FOREIGN KEY("project_id") REFERENCES "fm_projects"("project_id") ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY("language_id") REFERENCES "fm_proglangs"("language_id") ON UPDATE CASCADE ON DELETE CASCADE, PRIMARY KEY("project_id","language_id"));');
// indices
$sqlite->exec('CREATE INDEX "blog_posts_user_foreign" ON "fm_blog_posts" ("user_id");');
$sqlite->exec('CREATE INDEX "post_published" ON "fm_blog_posts" ("post_published");');
$sqlite->exec('CREATE INDEX "post_safe" ON "fm_blog_posts" ("post_safe");');
$sqlite->exec('CREATE UNIQUE INDEX "blog_tags_slug_unique" ON "fm_blog_tags" ("tag_slug");');
$sqlite->exec('CREATE UNIQUE INDEX "blog_post_tag_unique" ON "fm_blog_posts_tags" ("post_id", "tag_id");');
$sqlite->exec('CREATE INDEX "blog_post_tag_foreign" ON "fm_blog_posts_tags" ("tag_id");');
$sqlite->exec('CREATE UNIQUE INDEX "blog_wordpress_post_foreign" ON "fm_blog_wordpress" ("post_id");');
$sqlite->exec('CREATE UNIQUE INDEX "blog_wordpress_id_unique" ON "fm_blog_wordpress" ("wordpress_id");');
$sqlite->exec('CREATE UNIQUE INDEX "blog_wordpress_name_unique" ON "fm_blog_wordpress" ("wordpress_name");');
$sqlite->exec('CREATE UNIQUE INDEX "language_name" ON "fm_proglangs" ("language_name");');
$sqlite->exec('CREATE UNIQUE INDEX "project_name" ON "fm_projects" ("project_name");');
$sqlite->exec('CREATE UNIQUE INDEX "project_name_clean" ON "fm_projects" ("project_name_clean");');
$sqlite->exec('CREATE INDEX "project_order" ON "fm_projects" ("project_order");');
$sqlite->exec('CREATE INDEX "project_type" ON "fm_projects" ("project_type");');
$sqlite->exec('CREATE INDEX "project_archived" ON "fm_projects" ("project_archived");');
$sqlite->exec('CREATE INDEX "project_deleted" ON "fm_projects" ("project_deleted");');
$sqlite->exec('CREATE INDEX "project_created" ON "fm_projects" ("project_created");');
$sqlite->exec('CREATE INDEX "project_featured" ON "fm_projects" ("project_featured");');
$sqlite->exec('CREATE UNIQUE INDEX "projects_proglangs_unique" ON "fm_projects_proglangs" ("project_id", "language_id");');
$sqlite->exec('CREATE INDEX "projects_proglangs_language_foreign" ON "fm_projects_proglangs" ("language_id");');
$sqlite->exec('CREATE INDEX "projects_proglangs_priority_index" ON "fm_projects_proglangs" ("priority");');
$rows = $pdo->query('SELECT *, UNIX_TIMESTAMP(`post_created`) AS `post_created`, UNIX_TIMESTAMP(`post_published`) AS `post_published`, UNIX_TIMESTAMP(`post_deleted`) AS `post_deleted` FROM `fm_blog_posts`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_blog_posts` (`post_id`, `user_id`, `post_created`, `post_published`, `post_updated`, `post_deleted`, `post_safe`, `post_title`, `post_text`, `post_new_url`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->post_id);
$insert->bindValue(2, $row->user_id);
$insert->bindValue(3, $row->post_created);
$insert->bindValue(4, $row->post_published);
$insert->bindValue(5, $row->post_updated);
$insert->bindValue(6, $row->post_deleted);
$insert->bindValue(7, $row->post_safe);
$insert->bindValue(8, $row->post_title);
$insert->bindValue(9, $row->post_text);
$insert->bindValue(10, $row->post_new_url);
$insert->execute();
}
$rows = $pdo->query('SELECT *, UNIX_TIMESTAMP(`tag_created`) AS `tag_created` FROM `fm_blog_tags`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_blog_tags` (`tag_id`, `tag_name`, `tag_slug`, `tag_description`, `tag_created`) VALUES (?, ?, ?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->tag_id);
$insert->bindValue(2, $row->tag_name);
$insert->bindValue(3, $row->tag_slug);
$insert->bindValue(4, $row->tag_description);
$insert->bindValue(5, $row->tag_created);
$insert->execute();
}
$rows = $pdo->query('SELECT * FROM `fm_blog_posts_tags`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_blog_posts_tags` (`post_id`, `tag_id`) VALUES (?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->post_id);
$insert->bindValue(2, $row->tag_id);
$insert->execute();
}
$rows = $pdo->query('SELECT * FROM `fm_blog_wordpress`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_blog_wordpress` (`post_id`, `wordpress_id`, `wordpress_name`) VALUES (?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->post_id);
$insert->bindValue(2, $row->wordpress_id);
$insert->bindValue(3, $row->wordpress_name);
$insert->execute();
}
$rows = $pdo->query('SELECT * FROM `fm_proglangs`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_proglangs` (`language_id`, `language_name`, `language_colour`) VALUES (?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->language_id);
$insert->bindValue(2, $row->language_name);
$insert->bindValue(3, $row->language_colour);
$insert->execute();
}
$rows = $pdo->query('SELECT *, UNIX_TIMESTAMP(`project_created`) AS `project_created`, UNIX_TIMESTAMP(`project_archived`) AS `project_archived`, UNIX_TIMESTAMP(`project_deleted`) AS `project_deleted` FROM `fm_projects`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_projects` (`project_id`, `project_name`, `project_name_clean`, `project_summary`, `project_description`, `project_order`, `project_type`, `project_featured`, `project_colour`, `project_homepage`, `project_repository`, `project_forum`, `project_created`, `project_deleted`, `project_archived`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->project_id);
$insert->bindValue(2, $row->project_name);
$insert->bindValue(3, $row->project_name_clean);
$insert->bindValue(4, $row->project_summary);
$insert->bindValue(5, $row->project_description);
$insert->bindValue(6, $row->project_order);
$insert->bindValue(7, $row->project_type);
$insert->bindValue(8, $row->project_featured);
$insert->bindValue(9, $row->project_colour);
$insert->bindValue(10, $row->project_homepage);
$insert->bindValue(11, $row->project_repository);
$insert->bindValue(12, $row->project_forum);
$insert->bindValue(13, $row->project_created);
$insert->bindValue(14, $row->project_deleted);
$insert->bindValue(15, $row->project_archived);
$insert->execute();
}
$rows = $pdo->query('SELECT * FROM `fm_projects_proglangs`')->fetchAll(PDO::FETCH_OBJ);
$insert = $sqlite->prepare('INSERT INTO `fm_projects_proglangs` (`project_id`, `language_id`, `priority`) VALUES (?, ?, ?)');
foreach($rows as $row) {
$insert->bindValue(1, $row->project_id);
$insert->bindValue(2, $row->language_id);
$insert->bindValue(3, $row->priority);
$insert->execute();
}
$sqlite->close();
header('Content-Type: application/vnd.sqlite3');
header('Content-Disposition: attachment; filename="v4.db"');
echo file_get_contents($dbName);