Permalink
Browse files

migrate from using table and column prefixes

  • Loading branch information...
1 parent 3aae75d commit 80fac2d3119af3e509e66e41b3d2842217ce5410 @craigh committed Jul 20, 2011
Showing with 75 additions and 27 deletions.
  1. +49 −0 src/modules/PostCalendar/lib/PostCalendar/Installer.php
  2. +26 −27 src/modules/PostCalendar/tables.php
@@ -124,6 +124,7 @@ public function upgrade($oldversion)
if (ModUtil::available('Content')) {
Content_Installer::updateContentType('PostCalendar');
}
+ $this->removeTableColumnPrefixes();
// upgrade table structure
if (!DBUtil::changeTable('postcalendar_events')) {
LogUtil::registerError($this->__('Error! Could not upgrade the tables.'));
@@ -277,6 +278,54 @@ private function _createdefaultsubcategory()
LogUtil::registerStatus($this->__("PostCalendar: Initial sub-category created (Events)."));
return true;
}
+
+ private function removeTableColumnPrefixes()
+ {
+ $prefix = $this->serviceManager['prefix'];
+ $connection = Doctrine_Manager::getInstance()->getConnection('default');
+ $sqlStatements = array();
+ // N.B. statements generated with PHPMyAdmin
+ $sqlStatements[] = 'RENAME TABLE ' . $prefix . '_postcalendar_events' . " TO `postcalendar_events`";
+ // this removes the prefixes but also changes hideonindex to displayonindex and disallowcomments to allowcomments
+ // because 'from' and 'to' are reserved sql words, the column names are changed to ffrom and tto respectively
+ $sqlStatements[] = "ALTER TABLE `postcalendar_events`
+CHANGE `pc_eid` `eid` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
+CHANGE `pc_aid` `aid` VARCHAR( 30 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
+CHANGE `pc_title` `title` VARCHAR( 150 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
+CHANGE `pc_time` `ttime` DATETIME NULL DEFAULT NULL ,
+CHANGE `pc_hometext` `hometext` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
+CHANGE `pc_informant` `informant` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
+CHANGE `pc_eventDate` `eventDate` DATE NOT NULL DEFAULT '0000-00-00',
+CHANGE `pc_duration` `duration` BIGINT( 20 ) NOT NULL DEFAULT '0',
+CHANGE `pc_endDate` `endDate` DATE NOT NULL DEFAULT '0000-00-00',
+CHANGE `pc_recurrtype` `recurrtype` TINYINT( 4 ) NOT NULL DEFAULT '0',
+CHANGE `pc_recurrspec` `recurrspec` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
+CHANGE `pc_startTime` `startTime` VARCHAR(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '00:00:00',
+CHANGE `pc_alldayevent` `alldayevent` TINYINT(4) NOT NULL DEFAULT '0',
+CHANGE `pc_location` `location` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
+CHANGE `pc_conttel` `conttel` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
+CHANGE `pc_contname` `contname` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
+CHANGE `pc_contemail` `contemail` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
+CHANGE `pc_website` `website` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
+CHANGE `pc_fee` `fee` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
+CHANGE `pc_eventstatus` `eventstatus` INT(11) NOT NULL DEFAULT '0',
+CHANGE `pc_sharing` `sharing` INT( 11 ) NOT NULL DEFAULT '0',
+CHANGE `pc_hooked_modulename` `hooked_modulename` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
+CHANGE `pc_hooked_objectid` `hooked_objectid` BIGINT( 20 ) NULL DEFAULT '0',
+CHANGE `pc_hooked_area` `hooked_area` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
+CHANGE `pc_obj_status` `obj_status` VARCHAR( 1 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'A',
+CHANGE `pc_cr_date` `cr_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00',
+CHANGE `pc_cr_uid` `cr_uid` INT( 11 ) NOT NULL DEFAULT '0',
+CHANGE `pc_lu_date` `lu_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00',
+CHANGE `pc_lu_uid` `lu_uid` INT( 11 ) NOT NULL DEFAULT '0'";
+ foreach ($sqlStatements as $sql) {
+ $stmt = $connection->prepare($sql);
+ try {
+ $stmt->execute();
+ } catch (Exception $e) {
+ }
+ }
+ }
public static function LegacyContentTypeMap()
{
@@ -15,33 +15,32 @@ function postcalendar_tables()
// Initialise table array
$table = array();
- $pc_events = DBUtil::getLimitedTablename('postcalendar_events');
- $table['postcalendar_events'] = $pc_events;
+ $table['postcalendar_events'] = 'postcalendar_events';
$table['postcalendar_events_column'] = array(
- 'eid' => 'pc_eid', // event ID
- 'aid' => 'pc_aid', // participant's user ID (default:informant UID)
- 'title' => 'pc_title', // event title
- 'time' => 'pc_time', // record timestamp
- 'hometext' => 'pc_hometext', // event description
- 'informant' => 'pc_informant', // uid of event submittor
- 'eventDate' => 'pc_eventDate', // YYYY-MM-DD event start date
- 'duration' => 'pc_duration', // event duration (in seconds)
- 'endDate' => 'pc_endDate', // YYYY-MM-DD event end date (optional)
- 'recurrtype' => 'pc_recurrtype', // type of recurrance (0,1,2)
- 'recurrspec' => 'pc_recurrspec', // (serialized)
- 'startTime' => 'pc_startTime', // HH:MM:SS event start time
- 'alldayevent' => 'pc_alldayevent', // bool event all day or not
- 'location' => 'pc_location', // (serialized) event location
- 'conttel' => 'pc_conttel', // event contact phone
- 'contname' => 'pc_contname', // event contact name
- 'contemail' => 'pc_contemail', // event contact email
- 'website' => 'pc_website', // event website
- 'fee' => 'pc_fee', // event fee
- 'eventstatus' => 'pc_eventstatus', // event status (approved, pending)
- 'sharing' => 'pc_sharing', // event sharing (global, private, etc)
- 'hooked_modulename' => 'pc_hooked_modulename', // module name hooked to PC
- 'hooked_objectid' => 'pc_hooked_objectid', // object id hooked to PC
- 'hooked_area' => 'pc_hooked_area', // module area hooked to PC
+ 'eid' => 'eid', // event ID
+ 'aid' => 'aid', // participant's user ID (default:informant UID)
+ 'title' => 'title', // event title
+ 'time' => 'ttime', // record timestamp - NOT A TYPO! `time` is a reserved sql word
+ 'hometext' => 'hometext', // event description
+ 'informant' => 'informant', // uid of event submittor
+ 'eventDate' => 'eventDate', // YYYY-MM-DD event start date
+ 'duration' => 'duration', // event duration (in seconds)
+ 'endDate' => 'endDate', // YYYY-MM-DD event end date (optional)
+ 'recurrtype' => 'recurrtype', // type of recurrance (0,1,2)
+ 'recurrspec' => 'recurrspec', // (serialized)
+ 'startTime' => 'startTime', // HH:MM:SS event start time
+ 'alldayevent' => 'alldayevent', // bool event all day or not
+ 'location' => 'location', // (serialized) event location
+ 'conttel' => 'conttel', // event contact phone
+ 'contname' => 'contname', // event contact name
+ 'contemail' => 'contemail', // event contact email
+ 'website' => 'website', // event website
+ 'fee' => 'fee', // event fee
+ 'eventstatus' => 'eventstatus', // event status (approved, pending)
+ 'sharing' => 'sharing', // event sharing (global, private, etc)
+ 'hooked_modulename' => 'hooked_modulename', // module name hooked to PC
+ 'hooked_objectid' => 'hooked_objectid', // object id hooked to PC
+ 'hooked_area' => 'hooked_area', // module area hooked to PC
);
/**
* columns removed from previous versions:
@@ -84,7 +83,7 @@ function postcalendar_tables()
$table['postcalendar_events_primary_key_column'] = 'eid';
// add standard data fields
- ObjectUtil::addStandardFieldsToTableDefinition($table['postcalendar_events_column'], 'pc_');
+ ObjectUtil::addStandardFieldsToTableDefinition($table['postcalendar_events_column']);
ObjectUtil::addStandardFieldsToTableDataDefinition($table['postcalendar_events_column_def']);
// old tables for upgrade/renaming purposes

0 comments on commit 80fac2d

Please sign in to comment.