![]() |
Xataface Translation Memory Module 0.1
Translation Memory for Xataface Applications
|
00001 <?php 00002 /* 00003 * Xataface Translation Memory Module 00004 * Copyright (C) 2011 Steve Hannah <steve@weblite.ca> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public 00017 * License along with this library; if not, write to the 00018 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00022 class modules_tm_installer { 00023 00024 00025 00026 00027 public function update_1(){ 00028 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_records` ( 00029 `record_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 00030 `mtime` int(11) DEFAULT NULL, 00031 `translation_memory_id` int(11) NOT NULL DEFAULT '0', 00032 `last_string_extraction_time` int(11) DEFAULT NULL, 00033 `locked` tinyint(1) DEFAULT NULL, 00034 PRIMARY KEY (`record_id`,`translation_memory_id`) 00035 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; 00036 00037 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_record_strings` ( 00038 `record_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 00039 `string_id` int(11) NOT NULL, 00040 PRIMARY KEY (`record_id`,`string_id`) 00041 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 00042 "; 00043 00044 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_strings` ( 00045 `string_id` int(11) NOT NULL AUTO_INCREMENT, 00046 `language` varchar(2) COLLATE utf8_unicode_ci NOT NULL, 00047 `string_value` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, 00048 `normalized_value` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, 00049 `date_created` datetime DEFAULT NULL, 00050 `last_modified` datetime DEFAULT NULL, 00051 `hash` varchar(32) COLLATE utf8_unicode_ci NOT NULL, 00052 PRIMARY KEY (`string_id`) 00053 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 00054 "; 00055 00056 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_translations` ( 00057 `translation_id` int(11) NOT NULL AUTO_INCREMENT, 00058 `string_id` int(11) NOT NULL, 00059 `language` varchar(2) COLLATE utf8_unicode_ci NOT NULL, 00060 `translation_value` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, 00061 `normalized_translation_value` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, 00062 `date_created` datetime DEFAULT NULL, 00063 `last_modified` datetime DEFAULT NULL, 00064 `created_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, 00065 `translation_hash` varchar(32) COLLATE utf8_unicode_ci NOT NULL, 00066 PRIMARY KEY (`translation_id`), 00067 KEY `string_id` (`string_id`) 00068 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 00069 "; 00070 00071 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_translations_comments` ( 00072 `comment_id` int(11) NOT NULL AUTO_INCREMENT, 00073 `translation_id` int(11) NOT NULL, 00074 `translation_memory_id` int(11) NOT NULL, 00075 `posted_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, 00076 `date_created` datetime DEFAULT NULL, 00077 `last_modified` datetime DEFAULT NULL, 00078 `comments` text COLLATE utf8_unicode_ci, 00079 PRIMARY KEY (`comment_id`), 00080 KEY `translation_id` (`translation_id`) 00081 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 00082 "; 00083 00084 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_translations_score` ( 00085 `translation_memory_id` int(11) NOT NULL, 00086 `translation_id` int(11) NOT NULL, 00087 `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 00088 `score` int(11) NOT NULL, 00089 `date_created` datetime DEFAULT NULL, 00090 `last_modified` datetime DEFAULT NULL, 00091 PRIMARY KEY (`translation_memory_id`,`username`,`translation_id`) 00092 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 00093 "; 00094 00095 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_translations_status` ( 00096 `translation_status_id` int(11) NOT NULL AUTO_INCREMENT, 00097 `translation_memory_id` int(11) NOT NULL, 00098 `translation_id` int(11) NOT NULL, 00099 `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 00100 `status_id` int(11) NOT NULL, 00101 `date_created` datetime DEFAULT NULL, 00102 `last_modified` datetime DEFAULT NULL, 00103 PRIMARY KEY (`translation_status_id`), 00104 KEY `translation_memory_id` (`translation_memory_id`), 00105 KEY `translation_id` (`translation_id`), 00106 KEY `username` (`username`), 00107 KEY `status_id` (`status_id`) 00108 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 00109 "; 00110 00111 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_translation_memories` ( 00112 `translation_memory_id` int(11) NOT NULL AUTO_INCREMENT, 00113 `translation_memory_name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, 00114 `source_language` varchar(2) COLLATE utf8_unicode_ci NOT NULL, 00115 `destination_language` varchar(2) COLLATE utf8_unicode_ci NOT NULL, 00116 `date_created` datetime DEFAULT NULL, 00117 `last_modified` datetime DEFAULT NULL, 00118 `mtime` int(11) DEFAULT NULL, 00119 PRIMARY KEY (`translation_memory_id`) 00120 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 00121 "; 00122 00123 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_translation_memories_managers` ( 00124 `translation_memory_id` int(11) NOT NULL, 00125 `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 00126 PRIMARY KEY (`translation_memory_id`,`username`) 00127 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 00128 "; 00129 00130 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_translation_memory_translations` ( 00131 `translation_memory_id` int(11) NOT NULL, 00132 `translation_id` int(11) NOT NULL, 00133 PRIMARY KEY (`translation_memory_id`,`translation_id`) 00134 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 00135 "; 00136 00137 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_translation_statuses` ( 00138 `status_id` int(11) NOT NULL AUTO_INCREMENT, 00139 `status_name` int(11) NOT NULL, 00140 PRIMARY KEY (`status_id`) 00141 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 00142 "; 00143 00144 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_workflows` ( 00145 `workflow_id` int(11) NOT NULL AUTO_INCREMENT, 00146 `temp_translation_memory_id` int(11) NOT NULL, 00147 `translation_memory_id` int(11) NOT NULL, 00148 `created_by` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 00149 `current_step_id` int(11) NOT NULL, 00150 `date_created` datetime DEFAULT NULL, 00151 `last_modified` datetime DEFAULT NULL, 00152 PRIMARY KEY (`workflow_id`) 00153 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 00154 "; 00155 00156 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_workflow_records` ( 00157 `workflow_id` int(11) NOT NULL, 00158 `record_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 00159 PRIMARY KEY (`workflow_id`,`record_id`) 00160 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 00161 "; 00162 00163 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_workflow_steps` ( 00164 `workflow_step_id` int(11) NOT NULL AUTO_INCREMENT, 00165 `workflow_id` int(11) NOT NULL, 00166 `date_created` datetime DEFAULT NULL, 00167 `last_modified` datetime DEFAULT NULL, 00168 `step_number` int(5) NOT NULL, 00169 PRIMARY KEY (`workflow_step_id`) 00170 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 00171 "; 00172 00173 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_workflow_step_changes` ( 00174 `workflow_step_id` int(11) NOT NULL, 00175 `translations_log_id` int(11) NOT NULL, 00176 PRIMARY KEY (`workflow_step_id`,`translations_log_id`) 00177 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 00178 "; 00179 00180 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_workflow_step_panels` ( 00181 `panel_id` int(11) NOT NULL AUTO_INCREMENT, 00182 `workflow_step_id` int(11) NOT NULL, 00183 `panel_type_id` int(11) NOT NULL, 00184 `date_created` datetime DEFAULT NULL, 00185 `last_modified` datetime DEFAULT NULL, 00186 PRIMARY KEY (`panel_id`) 00187 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 00188 "; 00189 00190 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_workflow_step_panel_actions` ( 00191 `action_id` int(11) NOT NULL AUTO_INCREMENT, 00192 `workflow_step_id` int(11) NOT NULL, 00193 `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 00194 `action_type_id` int(11) NOT NULL, 00195 `date_created` datetime DEFAULT NULL, 00196 PRIMARY KEY (`action_id`) 00197 ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 00198 "; 00199 00200 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_workflow_step_panel_members` ( 00201 `panel_id` int(11) NOT NULL, 00202 `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 00203 PRIMARY KEY (`panel_id`,`username`) 00204 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 00205 "; 00206 00207 $sql[] = "CREATE TABLE IF NOT EXISTS `xf_tm_workflow_strings` ( 00208 `workflow_id` int(11) NOT NULL, 00209 `string_id` int(11) NOT NULL, 00210 PRIMARY KEY (`workflow_id`,`string_id`) 00211 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 00212 "; 00213 00214 self::query($sql); 00215 self::clearViews(); 00216 } 00217 00218 public function update_2(){ 00219 $sql[] = "ALTER TABLE `xf_tm_strings` ADD UNIQUE ( 00220 `language` , 00221 `hash` 00222 )"; 00223 self::query($sql); 00224 } 00225 00226 00227 public static function query($sql){ 00228 if ( is_array($sql) ){ 00229 $res = null; 00230 foreach ($sql as $q){ 00231 $res = self::query($q); 00232 } 00233 return $res; 00234 } else { 00235 $res = mysql_query($sql, df_db()); 00236 if ( !$res ) throw new Exception(mysql_error(df_db())); 00237 return $res; 00238 } 00239 00240 } 00241 00242 public static function clearViews(){ 00243 00244 00245 $res = mysql_query("show tables like 'dataface__view_%'", df_db()); 00246 $views = array(); 00247 while ( $row = mysql_fetch_row($res) ){ 00248 $views[] = $row[0]; 00249 } 00250 if ( $views ) { 00251 $sql = "drop view `".implode('`,`', $views)."`"; 00252 //echo $sql; 00253 //echo "<br/>"; 00254 $res = mysql_query("drop view `".implode('`,`', $views)."`", df_db()); 00255 if ( !$res ) throw new Exception(mysql_error(df_db())); 00256 } 00257 00258 } 00259 00260 }