Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine gedcom_news & user_blog modules #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions modules_v3/blog/db_schema/db_schema_0_1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
// Update the news/blog module database schema from version 0 to version 1
//
// Version 0: empty database
// Version 1: create the tables, as per PGV 4.2.1
//
// The script should assume that it can be interrupted at
// any point, and be able to continue by re-running the script.
// Fatal errors, however, should be allowed to throw exceptions,
// which will be caught by the framework.
// It shouldn't do anything that might take more than a few
// seconds, for systems with low timeout values.
//
// webtrees: Web based Family History software
// Copyright (C) 2013 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2009 Greg Roach
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
exit;
}

WT_DB::exec(
"CREATE TABLE IF NOT EXISTS `##news` (".
" n_id INTEGER AUTO_INCREMENT NOT NULL,".
" n_username VARCHAR(100) NOT NULL,".
" n_date INTEGER NOT NULL,".
" n_title VARCHAR(255) NOT NULL,".
" n_text TEXT NOT NULL,".
" PRIMARY KEY (n_id),".
" KEY ix1 (n_username)".
") COLLATE utf8_unicode_ci ENGINE=InnoDB"
);

// Update the version to indicate success
WT_Site::preference($schema_name, $next_version);
82 changes: 82 additions & 0 deletions modules_v3/blog/db_schema/db_schema_1_2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
// Update the news/blog module database schema from version 1 to version 2
//
// The script should assume that it can be interrupted at
// any point, and be able to continue by re-running the script.
// Fatal errors, however, should be allowed to throw exceptions,
// which will be caught by the framework.
// It shouldn't do anything that might take more than a few
// seconds, for systems with low timeout values.
//
// webtrees: Web based Family History software
// Copyright (C) 2013 webtrees development team.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
exit;
}

// Add new columns
try {
WT_DB::exec(
"ALTER TABLE `##news`".
" ADD user_id INTEGER NULL AFTER n_id,".
" ADD gedcom_id INTEGER NULL AFTER user_id,".
" ADD updated TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,".
" ADD KEY news_ix1 (user_id, updated),".
" ADD KEY news_ix2 (gedcom_id, updated)"
);
} catch (PDOException $ex) {
// Already updated?
}

// Migrate data from the old columns to the new ones
try {
WT_DB::exec(
"UPDATE `##news` n".
" LEFT JOIN `##gedcom` g ON (n.n_username=g.gedcom_name)".
" LEFT JOIN `##user` u ON (n.n_username=u.user_name)".
" SET n.gedcom_id=g.gedcom_id, n.user_id=u.user_id, updated=FROM_UNIXTIME(n_date)"
);
} catch (PDOException $ex) {
// Already updated?
}

// Delete orphaned rows
try {
WT_DB::exec(
"DELETE FROM `##news` WHERE user_id IS NULL AND gedcom_id IS NULL"
);
} catch (PDOException $ex) {
// Already updated?
}

// Delete/rename old columns
try {
WT_DB::exec(
"ALTER TABLE `##news`".
" DROP n_username, DROP n_date,".
" CHANGE n_id news_id INTEGER NOT NULL AUTO_INCREMENT,".
" CHANGE n_title subject VARCHAR(255) COLLATE utf8_unicode_ci,".
" CHANGE n_text body TEXT COLLATE utf8_unicode_ci"
);
} catch (PDOException $ex) {
// Already updated?
}

// Update the version to indicate success
WT_Site::preference($schema_name, $next_version);
53 changes: 53 additions & 0 deletions modules_v3/blog/db_schema/db_schema_2_3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
// Update the news/blog module database schema from version 2 to 3
// - add foreign key constraints
//
// The script should assume that it can be interrupted at
// any point, and be able to continue by re-running the script.
// Fatal errors, however, should be allowed to throw exceptions,
// which will be caught by the framework.
// It shouldn't do anything that might take more than a few
// seconds, for systems with low timeout values.
//
// webtrees: Web based Family History software
// Copyright (C) 2013 webtrees development team.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
exit;
}

// Delete any data that might violate the new constraints
WT_DB::exec(
"DELETE FROM `##news`".
" WHERE user_id NOT IN (SELECT user_id FROM `##user` )".
" OR gedcom_id NOT IN (SELECT gedcom_id FROM `##gedcom`)"
);

// Add the new constraints
try {
WT_DB::exec(
"ALTER TABLE `##news`".
" ADD FOREIGN KEY news_fk1 (user_id ) REFERENCES `##user` (user_id) ON DELETE CASCADE,".
" ADD FOREIGN KEY news_fk2 (gedcom_id) REFERENCES `##gedcom` (gedcom_id) ON DELETE CASCADE"
);
} catch (PDOException $ex) {
// Already updated?
}

// Update the version to indicate success
WT_Site::preference($schema_name, $next_version);
Loading