Replace copy_tables.php by a shell script (database alteration require admin privileges)
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 1 Mar 2010 21:02:07 +0000 (22:02 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 1 Mar 2010 21:02:07 +0000 (22:02 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
upgrade/account/copy_tables.php [deleted file]
upgrade/account/copy_tables.sh [new file with mode: 0755]
upgrade/account/update.sh
upgrade/inc/pervasive.sh

diff --git a/upgrade/account/copy_tables.php b/upgrade/account/copy_tables.php
deleted file mode 100755 (executable)
index 5186753..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-#!/usr/bin/php5 -q
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  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                *
- ***************************************************************************/
-
-require('./connect.db.inc.php');
-
-function copyTable($source, $target, $convertToInnoDB = true)
-{
-    XDB::execute('CREATE TABLE  ' . $target . '
-                          LIKE  ' . $source);
-    if ($convertToInnoDB) {
-        XDB::execute('ALTER TABLE  ' . $target . '
-                           ENGINE = InnoDB');
-    }
-    XDB::execute('INSERT INTO  ' . $target . '
-                       SELECT  *
-                         FROM  ' . $source);
-}
-
-copyTable('#forums#.list', 'forums');
-copyTable('#forums#.abos', 'forum_subs');
-copyTable('#forums#.innd', 'forum_innd');
-copyTable('#forums#.profils', 'forum_profiles');
-
-copyTable('#logger#.actions', 'log_actions');
-copyTable('#logger#.events', 'log_events');
-copyTable('#logger#.last_sessions', 'log_last_sessions');
-copyTable('#logger#.sessions', 'log_sessions');
-
-copyTable('#paiement#.paiements', 'payments');
-copyTable('#paiement#.codeC', 'payment_codeC');
-copyTable('#paiement#.codeRCB', 'payment_codeRCB');
-copyTable('#paiement#.methodes', 'payment_methods');
-copyTable('#paiement#.transactions', 'payment_transactions');
-
-copyTable('#groupex#.announces', 'group_announces');
-copyTable('#groupex#.announces_photo', 'group_announces_photo');
-copyTable('#groupex#.announces_read', 'group_announces_read');
-copyTable('#groupex#.asso', 'groups');
-copyTable('#groupex#.dom', 'group_dom');
-copyTable('#groupex#.evenements', 'group_events');
-copyTable('#groupex#.evenements_items', 'group_event_items');
-copyTable('#groupex#.evenements_participants', 'group_event_participants');
-copyTable('#groupex#.membres', 'group_members');
-copyTable('#groupex#.membres_sub_requests', 'group_member_sub_requests');
-copyTable('#x4dat#.groupesx_auth', 'group_auth');
-
-copyTable('#x4dat#.axletter', 'axletter');
-copyTable('#x4dat#.axletter_ins', 'axletter_ins');
-copyTable('#x4dat#.axletter_rights', 'axletter_rights');
-
-copyTable('#x4dat#.newsletter', 'newsletter');
-copyTable('#x4dat#.newsletter_art', 'newsletter_art');
-copyTable('#x4dat#.newsletter_cat', 'newsletter_cat');
-copyTable('#x4dat#.newsletter_ins', 'newsletter_ins');
-
-copyTable('#x4dat#.evenements', 'announces');
-copyTable('#x4dat#.evenements_photo', 'announce_photos');
-copyTable('#x4dat#.evenements_vus', 'announce_read');
-
-copyTable('#x4dat#.gapps_accounts', 'gapps_accounts', false);
-copyTable('#x4dat#.gapps_nicknames', 'gapps_nicknames', false);
-copyTable('#x4dat#.gapps_queue', 'gapps_queue');
-copyTable('#x4dat#.gapps_reporting', 'gapps_reporting');
-
-copyTable('#x4dat#.contacts', 'contacts');
-copyTable('#x4dat#.coupures', 'downtimes');
-copyTable('#x4dat#.emails_watch', 'email_watch');
-copyTable('#x4dat#.emails_send_save', 'email_send_save');
-copyTable('#x4dat#.homonymes', 'homonyms');
-copyTable('#x4dat#.ip_watch', 'ip_watch');
-copyTable('#x4dat#.mx_watch', 'mx_watch');
-copyTable('#x4dat#.ml_moderate', 'email_list_moderate');
-
-copyTable('#x4dat#.postfix_blacklist', 'postfix_blacklist');
-copyTable('#x4dat#.postfix_mailseen', 'postfix_mailseen');
-copyTable('#x4dat#.postfix_whitelist', 'postfix_whitelist');
-
-copyTable('#x4dat#.photo', 'profile_photos');
-copyTable('#x4dat#.binets_def', 'profile_binet_enum');
-copyTable('#x4dat#.binets_ins', 'profile_binets');
-copyTable('#x4dat#.sections', 'profile_section_enum');
-copyTable('#x4dat#.profile_medals', 'profile_medal_enum');
-copyTable('#x4dat#.profile_medals_sub', 'profile_medals');
-copyTable('#x4dat#.competences_def', 'profile_skill_enum');
-copyTable('#x4dat#.competences_ins', 'profile_skills');
-copyTable('#x4dat#.langues_def', 'profile_langskill_enum');
-copyTable('#x4dat#.langues_ins', 'profile_langskills');
-
-copyTable('#x4dat#.register_marketing', 'register_marketing');
-copyTable('#x4dat#.register_pending', 'register_pending');
-copyTable('#x4dat#.register_subs', 'register_subs');
-copyTable('#x4dat#.register_mstats', 'register_mstats');
-
-copyTable('#x4dat#.reminder', 'reminder');
-copyTable('#x4dat#.reminder_type', 'reminder_type');
-
-copyTable('#x4dat#.requests', 'requests');
-copyTable('#x4dat#.requests_answers', 'requests_answers');
-copyTable('#x4dat#.requests_hidden', 'requests_hidden');
-
-copyTable('#x4dat#.search_autocomplete', 'search_autocomplete');
-copyTable('#x4dat#.search_name', 'search_name');
-
-copyTable('#x4dat#.skins', 'skins');
-copyTable('#x4dat#.tips', 'tips');
-
-copyTable('#x4dat#.survey_surveys', 'surveys');
-copyTable('#x4dat#.survey_answers', 'survey_answers');
-copyTable('#x4dat#.survey_votes', 'survey_votes');
-
-copyTable('#x4dat#.watch_profile', 'watch_profile');
-copyTable('#x4dat#.perte_pass', 'account_lost_passwords');
-
-copyTable('#x4dat#.emails', 'emails');
-copyTable('#x4dat#.aliases', 'aliases');
-copyTable('#x4dat#.virtual', 'virtual');
-copyTable('#x4dat#.virtual_domains', 'virtual_domains');
-copyTable('#x4dat#.virtual_redirect', 'virtual_redirect');
-
-copyTable('#x4dat#.watch_nonins', 'watch_nonins');
-copyTable('#x4dat#.watch_promo', 'watch_promo');
-
-copyTable('#x4dat#.openid_trusted', 'account_auth_openid', false);
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/upgrade/account/copy_tables.sh b/upgrade/account/copy_tables.sh
new file mode 100755 (executable)
index 0000000..8f026c3
--- /dev/null
@@ -0,0 +1,116 @@
+#!/usr/bin/env bash
+
+copyTable() {
+    echo "CREATE TABLE $2 LIKE $1;"
+    if [ -z "$3" ] ; then
+        echo "ALTER TABLE $2 ENGINE = InnoDB;"
+    fi
+    echo "INSERT INTO $2 SELECT * FROM $1;"
+}
+
+
+copyTable '#forums#.list' 'forums'
+copyTable '#forums#.abos' 'forum_subs'
+copyTable '#forums#.innd' 'forum_innd'
+copyTable '#forums#.profils' 'forum_profiles'
+
+copyTable '#logger#.actions' 'log_actions'
+copyTable '#logger#.events' 'log_events'
+copyTable '#logger#.last_sessions' 'log_last_sessions'
+copyTable '#logger#.sessions' 'log_sessions'
+
+copyTable '#paiement#.paiements' 'payments'
+copyTable '#paiement#.codeC' 'payment_codeC'
+copyTable '#paiement#.codeRCB' 'payment_codeRCB'
+copyTable '#paiement#.methodes' 'payment_methods'
+copyTable '#paiement#.transactions' 'payment_transactions'
+
+copyTable '#groupex#.announces' 'group_announces'
+copyTable '#groupex#.announces_photo' 'group_announces_photo'
+copyTable '#groupex#.announces_read' 'group_announces_read'
+copyTable '#groupex#.asso' 'groups'
+copyTable '#groupex#.dom' 'group_dom'
+copyTable '#groupex#.evenements' 'group_events'
+copyTable '#groupex#.evenements_items' 'group_event_items'
+copyTable '#groupex#.evenements_participants' 'group_event_participants'
+copyTable '#groupex#.membres' 'group_members'
+copyTable '#groupex#.membres_sub_requests' 'group_member_sub_requests'
+copyTable '#x4dat#.groupesx_auth' 'group_auth'
+
+copyTable '#x4dat#.axletter' 'axletter'
+copyTable '#x4dat#.axletter_ins' 'axletter_ins'
+copyTable '#x4dat#.axletter_rights' 'axletter_rights'
+
+copyTable '#x4dat#.newsletter' 'newsletter'
+copyTable '#x4dat#.newsletter_art' 'newsletter_art'
+copyTable '#x4dat#.newsletter_cat' 'newsletter_cat'
+copyTable '#x4dat#.newsletter_ins' 'newsletter_ins'
+
+copyTable '#x4dat#.evenements' 'announces'
+copyTable '#x4dat#.evenements_photo' 'announce_photos'
+copyTable '#x4dat#.evenements_vus' 'announce_read'
+
+copyTable '#x4dat#.gapps_accounts' 'gapps_accounts' 'false'
+copyTable '#x4dat#.gapps_nicknames' 'gapps_nicknames' 'false'
+copyTable '#x4dat#.gapps_queue' 'gapps_queue'
+copyTable '#x4dat#.gapps_reporting' 'gapps_reporting'
+
+copyTable '#x4dat#.contacts' 'contacts'
+copyTable '#x4dat#.coupures' 'downtimes'
+copyTable '#x4dat#.emails_watch' 'email_watch'
+copyTable '#x4dat#.emails_send_save' 'email_send_save'
+copyTable '#x4dat#.homonymes' 'homonyms'
+copyTable '#x4dat#.ip_watch' 'ip_watch'
+copyTable '#x4dat#.mx_watch' 'mx_watch'
+copyTable '#x4dat#.ml_moderate' 'email_list_moderate'
+
+copyTable '#x4dat#.postfix_blacklist' 'postfix_blacklist'
+copyTable '#x4dat#.postfix_mailseen' 'postfix_mailseen'
+copyTable '#x4dat#.postfix_whitelist' 'postfix_whitelist'
+
+copyTable '#x4dat#.photo' 'profile_photos'
+copyTable '#x4dat#.binets_def' 'profile_binet_enum'
+copyTable '#x4dat#.binets_ins' 'profile_binets'
+copyTable '#x4dat#.sections' 'profile_section_enum'
+copyTable '#x4dat#.profile_medals' 'profile_medal_enum'
+copyTable '#x4dat#.profile_medals_sub' 'profile_medals'
+copyTable '#x4dat#.competences_def' 'profile_skill_enum'
+copyTable '#x4dat#.competences_ins' 'profile_skills'
+copyTable '#x4dat#.langues_def' 'profile_langskill_enum'
+copyTable '#x4dat#.langues_ins' 'profile_langskills'
+
+copyTable '#x4dat#.register_marketing' 'register_marketing'
+copyTable '#x4dat#.register_pending' 'register_pending'
+copyTable '#x4dat#.register_subs' 'register_subs'
+copyTable '#x4dat#.register_mstats' 'register_mstats'
+
+copyTable '#x4dat#.reminder' 'reminder'
+copyTable '#x4dat#.reminder_type' 'reminder_type'
+
+copyTable '#x4dat#.requests' 'requests'
+copyTable '#x4dat#.requests_answers' 'requests_answers'
+copyTable '#x4dat#.requests_hidden' 'requests_hidden'
+
+copyTable '#x4dat#.search_autocomplete' 'search_autocomplete'
+copyTable '#x4dat#.search_name' 'search_name'
+
+copyTable '#x4dat#.skins' 'skins'
+copyTable '#x4dat#.tips' 'tips'
+
+copyTable '#x4dat#.survey_surveys' 'surveys'
+copyTable '#x4dat#.survey_answers' 'survey_answers'
+copyTable '#x4dat#.survey_votes' 'survey_votes'
+
+copyTable '#x4dat#.watch_profile' 'watch_profile'
+copyTable '#x4dat#.perte_pass' 'account_lost_passwords'
+
+copyTable '#x4dat#.emails' 'emails'
+copyTable '#x4dat#.aliases' 'aliases'
+copyTable '#x4dat#.virtual' 'virtual'
+copyTable '#x4dat#.virtual_domains' 'virtual_domains'
+copyTable '#x4dat#.virtual_redirect' 'virtual_redirect'
+
+copyTable '#x4dat#.watch_nonins' 'watch_nonins'
+copyTable '#x4dat#.watch_promo' 'watch_promo'
+
+copyTable '#x4dat#.openid_trusted' 'account_auth_openid' 'false'
index a322ed9..49c65a2 100644 (file)
@@ -10,24 +10,17 @@ echo "* press ^D to start import (^C to cancel)"
 cat
 
 echo -n "* create database "
-(echo "CREATE DATABASE IF NOT EXISTS $DATABASE;" | $MYSQL) || die "ERROR"
+(echo "CREATE DATABASE IF NOT EXISTS $DATABASE;" | mysql_run) || die "ERROR"
 echo "OK"
 
 echo -n "* copying tables "
-./copy_tables.php || die "ERROR"
+(./copy_tables.php | mysql_run) || die "ERROR"
 echo "OK"
 
-for sql in ../newdirectory-0.0.1/*.sql
+for sql in ../newdirectory-0.0.1/*.sql *.sql
 do
     echo -n "* running $sql "
-    (sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" < $sql | $MYSQL $DATABASE >/dev/null) || die "ERROR"
-    echo "OK"
-done
-
-for sql in *.sql
-do
-    echo -n "* running $sql "
-    (sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" < $sql | $MYSQL $DATABASE >/dev/null) || die "ERROR"
+    (cat $sql | mysql_run) || die "ERROR"
     echo "OK"
 done
 
index 3eb0dae..b346707 100755 (executable)
@@ -22,6 +22,10 @@ function die() {
     exit 1
 }
 
+function mysql_run() {
+    sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" | $MYSQL $DATABASE
+}
+
 function mailman_stop() {
     echo -n "stops mailman"
     /etc/init.d/mailman stop &>/dev/null