cvs: pear /Translation2 Admin.php /Translation2/Admin/Container db.php mdb.php mdb2.php
| From: | Lorenzo Alberton | Date: | Thu, 02 Sep 2004 13:26:57 +0000 |
| Subject: | cvs: pear /Translation2 Admin.php /Translation2/Admin/Container db.php mdb.php mdb2.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-23581@lists.php.net to get a copy of this message | ||
quipo Thu Sep 2 09:26:57 2004 EDT
Modified files:
/pear/Translation2 Admin.php
/pear/Translation2/Admin/Container db.php mdb.php mdb2.php
Log:
fix createNewLang(), remove() and add new 'strings_default_table' optional field (Bugs
#2153 and #2248)
http://cvs.php.net/diff.php/pear/Translation2/Admin.php?r1=1.3&r2=1.4&ty=u Index: pear/Translation2/Admin.php diff -u pear/Translation2/Admin.php:1.3 pear/Translation2/Admin.php:1.4 --- pear/Translation2/Admin.php:1.3 Mon May 3 18:55:30 2004 +++ pear/Translation2/Admin.php Thu Sep 2 09:26:57 2004 @@ -16,11 +16,11 @@ // | Authors: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: Admin.php,v 1.3 2004/05/03 22:55:30 quipo Exp $ +// $Id: Admin.php,v 1.4 2004/09/02 13:26:57 quipo Exp $ // /** * @package Translation2 - * @version $Id: Admin.php,v 1.3 2004/05/03 22:55:30 quipo Exp $ + * @version $Id: Admin.php,v 1.4 2004/09/02 13:26:57 quipo Exp $ */ /** @@ -35,7 +35,7 @@ * with a common API for all the containers. * * @package Translation2 - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ class Translation2_Admin extends Translation2 { @@ -81,7 +81,7 @@ */ function createNewLang($langData) { - $res = $this->storage->createNewLang($langData['lang_id']); + $res = $this->storage->createNewLang($langData); if (PEAR::isError($res)) { return $res; } http://cvs.php.net/diff.php/pear/Translation2/Admin/Container/db.php?r1=1.7&r2=1.8&ty=u Index: pear/Translation2/Admin/Container/db.php diff -u pear/Translation2/Admin/Container/db.php:1.7 pear/Translation2/Admin/Container/db.php:1.8 --- pear/Translation2/Admin/Container/db.php:1.7 Wed Apr 28 07:12:10 2004 +++ pear/Translation2/Admin/Container/db.php Thu Sep 2 09:26:57 2004 @@ -5,22 +5,22 @@ // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2004 The PHP Group | // +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/3_0.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | +// | This source file is subject to version 3.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/3_0.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: db.php,v 1.7 2004/04/28 11:12:10 quipo Exp $ +// $Id: db.php,v 1.8 2004/09/02 13:26:57 quipo Exp $ // /** * @package Translation2 - * @version $Id: db.php,v 1.7 2004/04/28 11:12:10 quipo Exp $ + * @version $Id: db.php,v 1.8 2004/09/02 13:26:57 quipo Exp $ */ /** @@ -35,7 +35,7 @@ * by the PEAR DB abstraction layer to fetch data. * * @package Translation2 - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ */ class Translation2_Admin_Container_db extends Translation2_Container_db { @@ -43,17 +43,14 @@ // {{{ class vars // }}} - // {{{ createNewLang() - + // {{{ + /** - * Creates a new table to store the strings in this language. - * If the table is shared with other langs, it is ALTERed to - * hold strings in this lang too. - * - * @param string $langID - * @return mixed true on success, PEAR_Error on failure + * Fetch the table names from the db + * @access private + * @return mixed array on success, PEAR_Error on failure */ - function createNewLang($langID) + function _fetchTableNames() { $res = $this->query('SHOW TABLES', 'getAll'); if (PEAR::isError($res)) { @@ -62,16 +59,40 @@ if (empty($res) || !is_array($res)) { //return error } + $tables = array(); + foreach ($res as $record) { + $tables[] = $record[0]; + } + return $tables; + } + + // }}} + // {{{ createNewLang() - $lang_col = str_replace('%s', $langID, $this->options['string_text_col']); + /** + * Creates a new table to store the strings in this language. + * If the table is shared with other langs, it is ALTERed to + * hold strings in this lang too. + * + * @param array $langData + * @return mixed true on success, PEAR_Error on failure + */ + function createNewLang($langData) + { + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; + } + + $lang_col = str_replace('%s', $langData['lang_id'], $this->options['string_text_col']); if (empty($lang_col)) { $lang_col = $this->currentLang['id']; } - - if (in_array($this->options['strings_tables'][$langID], $res)) { + + if (in_array($langData['table_name'], $tables)) { //table exists - $query = sprintf('ALTER TABLE %s ADD COLUMN %s', - $this->options['strings_tables'][$langID], + $query = sprintf('ALTER TABLE %s ADD COLUMN %s TEXT', + $langData['table_name'], $lang_col ); } else { @@ -83,7 +104,7 @@ .'UNIQUE KEY tablekey (%s, %s), ' .'KEY page_id (%s), ' .'KEY string_id (%s))', - $this->options['strings_tables'][$langID], + $langData['table_name'], $this->options['string_page_id_col'], $this->options['string_id_col'], $lang_col, @@ -103,24 +124,21 @@ * Creates a new entry in the langsAvail table. * If the table doesn't exist yet, it is created. * - * @param array $langData array('lang_id' => 'en', - * 'table_name' => 'i18n', - * 'name' => 'english', - * 'meta' => 'some meta info', - * 'error_text' => 'not available'); + * @param array $langData array('lang_id' => 'en', + * 'table_name' => 'i18n', + * 'name' => 'english', + * 'meta' => 'some meta info', + * 'error_text' => 'not available'); * @return mixed true on success, PEAR_Error on failure */ function addLangToAvailList($langData) { - $res = $this->query('SHOW TABLES', 'getAll'); - if (PEAR::isError($res)) { - return $res; - } - if (empty($res) || !is_array($res)) { - //return error + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; } - if (!in_array($this->options['langs_avail_table'], $res)) { + if (!in_array($langData['table_name'], $tables)) { //is this query portable?? $query = sprintf('CREATE TABLE %s (' .'%s CHAR(16), ' @@ -331,9 +349,24 @@ $langs = $this->getLangs('ids'); $tables = array(); foreach ($langs as $langID) { - $tables[] = $this->options['strings_tables'][$langID]; + if (isset($this->options['strings_tables'][$langID])) { + $tables[] = $this->options['strings_tables'][$langID]; + } else { + $tables[] = $this->options['strings_default_table']; + } + } $tables = array_unique($tables); + //get the tables and remove the non existent ones from the list + $dbTables = $this->_fetchTableNames(); + if (!PEAR::isError($dbTables)) { + foreach ($tables as $k => $table) { + if (!in_array($table, $dbTables)) { + unset($tables[$k]); + } + } + } + foreach ($tables as $table) { $query = 'DELETE FROM '.$table.' WHERE '; $where = array(); http://cvs.php.net/diff.php/pear/Translation2/Admin/Container/mdb.php?r1=1.6&r2=1.7&ty=u Index: pear/Translation2/Admin/Container/mdb.php diff -u pear/Translation2/Admin/Container/mdb.php:1.6 pear/Translation2/Admin/Container/mdb.php:1.7 --- pear/Translation2/Admin/Container/mdb.php:1.6 Thu Apr 15 13:16:06 2004 +++ pear/Translation2/Admin/Container/mdb.php Thu Sep 2 09:26:57 2004 @@ -5,22 +5,22 @@ // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2004 The PHP Group | // +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/3_0.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | +// | This source file is subject to version 3.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/3_0.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: mdb.php,v 1.6 2004/04/15 17:16:06 quipo Exp $ +// $Id: mdb.php,v 1.7 2004/09/02 13:26:57 quipo Exp $ // /** * @package Translation2 - * @version $Id: mdb.php,v 1.6 2004/04/15 17:16:06 quipo Exp $ + * @version $Id: mdb.php,v 1.7 2004/09/02 13:26:57 quipo Exp $ */ /** @@ -35,7 +35,7 @@ * by the PEAR MDB abstraction layer to fetch data. * * @package Translation2 - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ class Translation2_Admin_Container_mdb extends Translation2_Container_mdb { @@ -44,17 +44,14 @@ // }}} - // {{{ createNewLang() + // {{{ /** - * Creates a new table to store the strings in this language. - * If the table is shared with other langs, it is ALTERed to - * hold strings in this lang too. - * - * @param string $langID - * @return mixed true on success, PEAR_Error on failure + * Fetch the table names from the db + * @access private + * @return mixed array on success, PEAR_Error on failure */ - function createNewLang($langID) + function _fetchTableNames() { $res = $this->query('SHOW TABLES', 'getAll'); if (PEAR::isError($res)) { @@ -63,16 +60,40 @@ if (empty($res) || !is_array($res)) { //return error } + $tables = array(); + foreach ($res as $record) { + $tables[] = $record[0]; + } + return $tables; + } + + // }}} + // {{{ createNewLang() + + /** + * Creates a new table to store the strings in this language. + * If the table is shared with other langs, it is ALTERed to + * hold strings in this lang too. + * + * @param array $langData + * @return mixed true on success, PEAR_Error on failure + */ + function createNewLang($langData) + { + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; + } - $lang_col = str_replace('%s', $langID, $this->options['string_text_col']); + $lang_col = str_replace('%s', $langData['lang_id'], $this->options['string_text_col']); if (empty($lang_col)) { $lang_col = $this->currentLang['id']; } - if (in_array($this->options['strings_tables'][$langID], $res)) { + if (in_array($langData['table_name'], $tables)) { //table exists - $query = sprintf('ALTER TABLE %s ADD COLUMN %s', - $this->options['strings_tables'][$langID], + $query = sprintf('ALTER TABLE %s ADD COLUMN %s TEXT', + $langData['table_name'], $lang_col ); } else { @@ -84,7 +105,7 @@ .'UNIQUE KEY tablekey (%s, %s), ' .'KEY page_id (%s), ' .'KEY string_id (%s))', - $this->options['strings_tables'][$langID], + $langData['table_name'], $this->options['string_page_id_col'], $this->options['string_id_col'], $lang_col, @@ -104,24 +125,21 @@ * Creates a new entry in the langsAvail table. * If the table doesn't exist yet, it is created. * - * @param array $langData array('lang_id' => 'en', - * 'table_name' => 'i18n', - * 'name' => 'english', - * 'meta' => 'some meta info', - * 'error_text' => 'not available'); + * @param array $langData array('lang_id' => 'en', + * 'table_name' => 'i18n', + * 'name' => 'english', + * 'meta' => 'some meta info', + * 'error_text' => 'not available'); * @return mixed true on success, PEAR_Error on failure */ function addLangToAvailList($langData) { - $res = $this->query('SHOW TABLES', 'getAll'); - if (PEAR::isError($res)) { - return $res; - } - if (empty($res) || !is_array($res)) { - //return error + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; } - if (!in_array($this->options['langs_avail_table'], $res)) { + if (!in_array($langData['table_name'], $tables)) { //is this query portable?? $query = sprintf('CREATE TABLE %s (' .'%s CHAR(16), ' @@ -200,17 +218,17 @@ } if ($oneQuery) { - $fields = array( - $this->options['string_id_col'] => array( - 'Type' => 'text', - 'Value' => $stringID, - 'Key' => true - ), - $this->options['string_page_id_col'] => array( - 'Type' => 'text', - 'Value' => $pageID, - 'Null' => (is_null($pageID) ? true : false) - ), + $fields = array( + $this->options['string_id_col'] => array( + 'Type' => 'text', + 'Value' => $stringID, + 'Key' => true + ), + $this->options['string_page_id_col'] => array( + 'Type' => 'text', + 'Value' => $pageID, + 'Null' => (is_null($pageID) ? true : false) + ), ); foreach ($langs as $langID) { $lang_col = str_replace('%s', $langID, $this->options['string_text_col']); @@ -219,7 +237,7 @@ 'Value' => $stringArray[$langID], ); } - + $res = $this->db->replace($this->options['strings_tables'][$langs[0]], $fields); if (PEAR::isError($res)) { return $res; @@ -231,21 +249,21 @@ $lang_col = $langID; } - $fields = array( - $this->options['string_id_col'] => array( - 'Type' => 'text', - 'Value' => $stringID, - 'Key' => true - ), - $this->options['string_page_id_col'] => array( - 'Type' => 'text', - 'Value' => $pageID, - 'Null' => (is_null($pageID) ? true : false) + $fields = array( + $this->options['string_id_col'] => array( + 'Type' => 'text', + 'Value' => $stringID, + 'Key' => true + ), + $this->options['string_page_id_col'] => array( + 'Type' => 'text', + 'Value' => $pageID, + 'Null' => (is_null($pageID) ? true : false) + ), + $lang_col => array( + 'Type' => 'text', + 'Value' => $stringArray[$langID] ), - $lang_col => array( - 'Type' => 'text', - 'Value' => $stringArray[$langID] - ), ); $res = $this->db->replace($this->options['strings_tables'][$langID], $fields); if (PEAR::isError($res)) { @@ -272,9 +290,24 @@ $langs = $this->getLangs('ids'); $tables = array(); foreach ($langs as $langID) { - $tables[] = $this->options['strings_tables'][$langID]; + if (isset($this->options['strings_tables'][$langID])) { + $tables[] = $this->options['strings_tables'][$langID]; + } else { + $tables[] = $this->options['strings_default_table']; + } + } $tables = array_unique($tables); + //get the tables and remove the non existent ones from the list + $dbTables = $this->_fetchTableNames(); + if (!PEAR::isError($dbTables)) { + foreach ($tables as $k => $table) { + if (!in_array($table, $dbTables)) { + unset($tables[$k]); + } + } + } + foreach ($tables as $table) { $query = 'DELETE FROM '.$table.' WHERE '; $where = array(); http://cvs.php.net/diff.php/pear/Translation2/Admin/Container/mdb2.php?r1=1.5&r2=1.6&ty=u Index: pear/Translation2/Admin/Container/mdb2.php diff -u pear/Translation2/Admin/Container/mdb2.php:1.5 pear/Translation2/Admin/Container/mdb2.php:1.6 --- pear/Translation2/Admin/Container/mdb2.php:1.5 Mon Apr 19 10:55:50 2004 +++ pear/Translation2/Admin/Container/mdb2.php Thu Sep 2 09:26:57 2004 @@ -5,22 +5,22 @@ // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2004 The PHP Group | // +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/3_0.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | +// | This source file is subject to version 3.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/3_0.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: mdb2.php,v 1.5 2004/04/19 14:55:50 quipo Exp $ +// $Id: mdb2.php,v 1.6 2004/09/02 13:26:57 quipo Exp $ // /** * @package Translation2 - * @version $Id: mdb2.php,v 1.5 2004/04/19 14:55:50 quipo Exp $ + * @version $Id: mdb2.php,v 1.6 2004/09/02 13:26:57 quipo Exp $ */ /** @@ -35,7 +35,7 @@ * by the PEAR MDB2 abstraction layer to fetch data. * * @package Translation2 - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ class Translation2_Admin_Container_mdb2 extends Translation2_Container_mdb2 { @@ -44,17 +44,14 @@ // }}} - // {{{ createNewLang() + // {{{ /** - * Creates a new table to store the strings in this language. - * If the table is shared with other langs, it is ALTERed to - * hold strings in this lang too. - * - * @param string $langID - * @return mixed true on success, PEAR_Error on failure + * Fetch the table names from the db + * @access private + * @return mixed array on success, PEAR_Error on failure */ - function createNewLang($langID) + function _fetchTableNames() { $res = $this->query('SHOW TABLES', 'queryAll'); if (PEAR::isError($res)) { @@ -63,16 +60,40 @@ if (empty($res) || !is_array($res)) { //return error } + $tables = array(); + foreach ($res as $record) { + $tables[] = $record[0]; + } + return $tables; + } + + // }}} + // {{{ createNewLang() + + /** + * Creates a new table to store the strings in this language. + * If the table is shared with other langs, it is ALTERed to + * hold strings in this lang too. + * + * @param array $langData + * @return mixed true on success, PEAR_Error on failure + */ + function createNewLang($langData) + { + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; + } - $lang_col = str_replace('%s', $langID, $this->options['string_text_col']); + $lang_col = str_replace('%s', $langData['lang_id'], $this->options['string_text_col']); if (empty($lang_col)) { $lang_col = $this->currentLang['id']; } - if (in_array($this->options['strings_tables'][$langID], $res)) { + if (in_array($langData['table_name'], $tables)) { //table exists - $query = sprintf('ALTER TABLE %s ADD COLUMN %s', - $this->options['strings_tables'][$langID], + $query = sprintf('ALTER TABLE %s ADD COLUMN %s TEXT', + $langData['table_name'], $lang_col ); } else { @@ -84,7 +105,7 @@ .'UNIQUE KEY tablekey (%s, %s), ' .'KEY page_id (%s), ' .'KEY string_id (%s))', - $this->options['strings_tables'][$langID], + $langData['table_name'], $this->options['string_page_id_col'], $this->options['string_id_col'], $lang_col, @@ -104,24 +125,21 @@ * Creates a new entry in the langsAvail table. * If the table doesn't exist yet, it is created. * - * @param array $langData array('lang_id' => 'en', - * 'table_name' => 'i18n', - * 'name' => 'english', - * 'meta' => 'some meta info', - * 'error_text' => 'not available'); + * @param array $langData array('lang_id' => 'en', + * 'table_name' => 'i18n', + * 'name' => 'english', + * 'meta' => 'some meta info', + * 'error_text' => 'not available'); * @return mixed true on success, PEAR_Error on failure */ function addLangToAvailList($langData) { - $res = $this->query('SHOW TABLES', 'queryAll'); - if (PEAR::isError($res)) { - return $res; - } - if (empty($res) || !is_array($res)) { - //return error + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; } - if (!in_array($this->options['langs_avail_table'], $res)) { + if (!in_array($langData['table_name'], $tables)) { //is this query portable?? $query = sprintf('CREATE TABLE %s (' .'%s CHAR(16), ' @@ -200,17 +218,17 @@ } if ($oneQuery) { - $fields = array( - $this->options['string_id_col'] => array( - 'type' => 'text', - 'value' => $stringID, - 'key' => true - ), - $this->options['string_page_id_col'] => array( - 'type' => 'text', - 'value' => $pageID, - 'null' => (is_null($pageID) ? true : false) - ), + $fields = array( + $this->options['string_id_col'] => array( + 'type' => 'text', + 'value' => $stringID, + 'key' => true + ), + $this->options['string_page_id_col'] => array( + 'type' => 'text', + 'value' => $pageID, + 'null' => (is_null($pageID) ? true : false) + ), ); foreach ($langs as $langID) { $lang_col = str_replace('%s', $langID, $this->options['string_text_col']); @@ -219,7 +237,7 @@ 'value' => $stringArray[$langID], ); } - + $res = $this->db->replace($this->options['strings_tables'][$langs[0]], $fields); if (PEAR::isError($res)) { return $res; @@ -231,21 +249,21 @@ $lang_col = $langID; } - $fields = array( - $this->options['string_id_col'] => array( - 'type' => 'text', - 'value' => $stringID, - 'key' => true - ), - $this->options['string_page_id_col'] => array( - 'type' => 'text', - 'value' => $pageID, - 'null' => (is_null($pageID) ? true : false) + $fields = array( + $this->options['string_id_col'] => array( + 'type' => 'text', + 'value' => $stringID, + 'key' => true + ), + $this->options['string_page_id_col'] => array( + 'type' => 'text', + 'value' => $pageID, + 'null' => (is_null($pageID) ? true : false) + ), + $lang_col => array( + 'type' => 'text', + 'value' => $stringArray[$langID] ), - $lang_col => array( - 'type' => 'text', - 'value' => $stringArray[$langID] - ), ); $res = $this->db->replace($this->options['strings_tables'][$langID], $fields); if (PEAR::isError($res)) { @@ -272,9 +290,24 @@ $langs = $this->getLangs('ids'); $tables = array(); foreach ($langs as $langID) { - $tables[] = $this->options['strings_tables'][$langID]; + if (isset($this->options['strings_tables'][$langID])) { + $tables[] = $this->options['strings_tables'][$langID]; + } else { + $tables[] = $this->options['strings_default_table']; + } + } $tables = array_unique($tables); + //get the tables and remove the non existent ones from the list + $dbTables = $this->_fetchTableNames(); + if (!PEAR::isError($dbTables)) { + foreach ($tables as $k => $table) { + if (!in_array($table, $dbTables)) { + unset($tables[$k]); + } + } + } + foreach ($tables as $table) { $query = 'DELETE FROM '.$table.' WHERE '; $where = array();
http://cvs.php.net/diff.php/pear/Translation2/Admin.php?r1=1.3&r2=1.4&ty=u Index: pear/Translation2/Admin.php diff -u pear/Translation2/Admin.php:1.3 pear/Translation2/Admin.php:1.4 --- pear/Translation2/Admin.php:1.3 Mon May 3 18:55:30 2004 +++ pear/Translation2/Admin.php Thu Sep 2 09:26:57 2004 @@ -16,11 +16,11 @@ // | Authors: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: Admin.php,v 1.3 2004/05/03 22:55:30 quipo Exp $ +// $Id: Admin.php,v 1.4 2004/09/02 13:26:57 quipo Exp $ // /** * @package Translation2 - * @version $Id: Admin.php,v 1.3 2004/05/03 22:55:30 quipo Exp $ + * @version $Id: Admin.php,v 1.4 2004/09/02 13:26:57 quipo Exp $ */ /** @@ -35,7 +35,7 @@ * with a common API for all the containers. * * @package Translation2 - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ class Translation2_Admin extends Translation2 { @@ -81,7 +81,7 @@ */ function createNewLang($langData) { - $res = $this->storage->createNewLang($langData['lang_id']); + $res = $this->storage->createNewLang($langData); if (PEAR::isError($res)) { return $res; } http://cvs.php.net/diff.php/pear/Translation2/Admin/Container/db.php?r1=1.7&r2=1.8&ty=u Index: pear/Translation2/Admin/Container/db.php diff -u pear/Translation2/Admin/Container/db.php:1.7 pear/Translation2/Admin/Container/db.php:1.8 --- pear/Translation2/Admin/Container/db.php:1.7 Wed Apr 28 07:12:10 2004 +++ pear/Translation2/Admin/Container/db.php Thu Sep 2 09:26:57 2004 @@ -5,22 +5,22 @@ // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2004 The PHP Group | // +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/3_0.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | +// | This source file is subject to version 3.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/3_0.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: db.php,v 1.7 2004/04/28 11:12:10 quipo Exp $ +// $Id: db.php,v 1.8 2004/09/02 13:26:57 quipo Exp $ // /** * @package Translation2 - * @version $Id: db.php,v 1.7 2004/04/28 11:12:10 quipo Exp $ + * @version $Id: db.php,v 1.8 2004/09/02 13:26:57 quipo Exp $ */ /** @@ -35,7 +35,7 @@ * by the PEAR DB abstraction layer to fetch data. * * @package Translation2 - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ */ class Translation2_Admin_Container_db extends Translation2_Container_db { @@ -43,17 +43,14 @@ // {{{ class vars // }}} - // {{{ createNewLang() - + // {{{ + /** - * Creates a new table to store the strings in this language. - * If the table is shared with other langs, it is ALTERed to - * hold strings in this lang too. - * - * @param string $langID - * @return mixed true on success, PEAR_Error on failure + * Fetch the table names from the db + * @access private + * @return mixed array on success, PEAR_Error on failure */ - function createNewLang($langID) + function _fetchTableNames() { $res = $this->query('SHOW TABLES', 'getAll'); if (PEAR::isError($res)) { @@ -62,16 +59,40 @@ if (empty($res) || !is_array($res)) { //return error } + $tables = array(); + foreach ($res as $record) { + $tables[] = $record[0]; + } + return $tables; + } + + // }}} + // {{{ createNewLang() - $lang_col = str_replace('%s', $langID, $this->options['string_text_col']); + /** + * Creates a new table to store the strings in this language. + * If the table is shared with other langs, it is ALTERed to + * hold strings in this lang too. + * + * @param array $langData + * @return mixed true on success, PEAR_Error on failure + */ + function createNewLang($langData) + { + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; + } + + $lang_col = str_replace('%s', $langData['lang_id'], $this->options['string_text_col']); if (empty($lang_col)) { $lang_col = $this->currentLang['id']; } - - if (in_array($this->options['strings_tables'][$langID], $res)) { + + if (in_array($langData['table_name'], $tables)) { //table exists - $query = sprintf('ALTER TABLE %s ADD COLUMN %s', - $this->options['strings_tables'][$langID], + $query = sprintf('ALTER TABLE %s ADD COLUMN %s TEXT', + $langData['table_name'], $lang_col ); } else { @@ -83,7 +104,7 @@ .'UNIQUE KEY tablekey (%s, %s), ' .'KEY page_id (%s), ' .'KEY string_id (%s))', - $this->options['strings_tables'][$langID], + $langData['table_name'], $this->options['string_page_id_col'], $this->options['string_id_col'], $lang_col, @@ -103,24 +124,21 @@ * Creates a new entry in the langsAvail table. * If the table doesn't exist yet, it is created. * - * @param array $langData array('lang_id' => 'en', - * 'table_name' => 'i18n', - * 'name' => 'english', - * 'meta' => 'some meta info', - * 'error_text' => 'not available'); + * @param array $langData array('lang_id' => 'en', + * 'table_name' => 'i18n', + * 'name' => 'english', + * 'meta' => 'some meta info', + * 'error_text' => 'not available'); * @return mixed true on success, PEAR_Error on failure */ function addLangToAvailList($langData) { - $res = $this->query('SHOW TABLES', 'getAll'); - if (PEAR::isError($res)) { - return $res; - } - if (empty($res) || !is_array($res)) { - //return error + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; } - if (!in_array($this->options['langs_avail_table'], $res)) { + if (!in_array($langData['table_name'], $tables)) { //is this query portable?? $query = sprintf('CREATE TABLE %s (' .'%s CHAR(16), ' @@ -331,9 +349,24 @@ $langs = $this->getLangs('ids'); $tables = array(); foreach ($langs as $langID) { - $tables[] = $this->options['strings_tables'][$langID]; + if (isset($this->options['strings_tables'][$langID])) { + $tables[] = $this->options['strings_tables'][$langID]; + } else { + $tables[] = $this->options['strings_default_table']; + } + } $tables = array_unique($tables); + //get the tables and remove the non existent ones from the list + $dbTables = $this->_fetchTableNames(); + if (!PEAR::isError($dbTables)) { + foreach ($tables as $k => $table) { + if (!in_array($table, $dbTables)) { + unset($tables[$k]); + } + } + } + foreach ($tables as $table) { $query = 'DELETE FROM '.$table.' WHERE '; $where = array(); http://cvs.php.net/diff.php/pear/Translation2/Admin/Container/mdb.php?r1=1.6&r2=1.7&ty=u Index: pear/Translation2/Admin/Container/mdb.php diff -u pear/Translation2/Admin/Container/mdb.php:1.6 pear/Translation2/Admin/Container/mdb.php:1.7 --- pear/Translation2/Admin/Container/mdb.php:1.6 Thu Apr 15 13:16:06 2004 +++ pear/Translation2/Admin/Container/mdb.php Thu Sep 2 09:26:57 2004 @@ -5,22 +5,22 @@ // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2004 The PHP Group | // +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/3_0.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | +// | This source file is subject to version 3.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/3_0.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: mdb.php,v 1.6 2004/04/15 17:16:06 quipo Exp $ +// $Id: mdb.php,v 1.7 2004/09/02 13:26:57 quipo Exp $ // /** * @package Translation2 - * @version $Id: mdb.php,v 1.6 2004/04/15 17:16:06 quipo Exp $ + * @version $Id: mdb.php,v 1.7 2004/09/02 13:26:57 quipo Exp $ */ /** @@ -35,7 +35,7 @@ * by the PEAR MDB abstraction layer to fetch data. * * @package Translation2 - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ class Translation2_Admin_Container_mdb extends Translation2_Container_mdb { @@ -44,17 +44,14 @@ // }}} - // {{{ createNewLang() + // {{{ /** - * Creates a new table to store the strings in this language. - * If the table is shared with other langs, it is ALTERed to - * hold strings in this lang too. - * - * @param string $langID - * @return mixed true on success, PEAR_Error on failure + * Fetch the table names from the db + * @access private + * @return mixed array on success, PEAR_Error on failure */ - function createNewLang($langID) + function _fetchTableNames() { $res = $this->query('SHOW TABLES', 'getAll'); if (PEAR::isError($res)) { @@ -63,16 +60,40 @@ if (empty($res) || !is_array($res)) { //return error } + $tables = array(); + foreach ($res as $record) { + $tables[] = $record[0]; + } + return $tables; + } + + // }}} + // {{{ createNewLang() + + /** + * Creates a new table to store the strings in this language. + * If the table is shared with other langs, it is ALTERed to + * hold strings in this lang too. + * + * @param array $langData + * @return mixed true on success, PEAR_Error on failure + */ + function createNewLang($langData) + { + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; + } - $lang_col = str_replace('%s', $langID, $this->options['string_text_col']); + $lang_col = str_replace('%s', $langData['lang_id'], $this->options['string_text_col']); if (empty($lang_col)) { $lang_col = $this->currentLang['id']; } - if (in_array($this->options['strings_tables'][$langID], $res)) { + if (in_array($langData['table_name'], $tables)) { //table exists - $query = sprintf('ALTER TABLE %s ADD COLUMN %s', - $this->options['strings_tables'][$langID], + $query = sprintf('ALTER TABLE %s ADD COLUMN %s TEXT', + $langData['table_name'], $lang_col ); } else { @@ -84,7 +105,7 @@ .'UNIQUE KEY tablekey (%s, %s), ' .'KEY page_id (%s), ' .'KEY string_id (%s))', - $this->options['strings_tables'][$langID], + $langData['table_name'], $this->options['string_page_id_col'], $this->options['string_id_col'], $lang_col, @@ -104,24 +125,21 @@ * Creates a new entry in the langsAvail table. * If the table doesn't exist yet, it is created. * - * @param array $langData array('lang_id' => 'en', - * 'table_name' => 'i18n', - * 'name' => 'english', - * 'meta' => 'some meta info', - * 'error_text' => 'not available'); + * @param array $langData array('lang_id' => 'en', + * 'table_name' => 'i18n', + * 'name' => 'english', + * 'meta' => 'some meta info', + * 'error_text' => 'not available'); * @return mixed true on success, PEAR_Error on failure */ function addLangToAvailList($langData) { - $res = $this->query('SHOW TABLES', 'getAll'); - if (PEAR::isError($res)) { - return $res; - } - if (empty($res) || !is_array($res)) { - //return error + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; } - if (!in_array($this->options['langs_avail_table'], $res)) { + if (!in_array($langData['table_name'], $tables)) { //is this query portable?? $query = sprintf('CREATE TABLE %s (' .'%s CHAR(16), ' @@ -200,17 +218,17 @@ } if ($oneQuery) { - $fields = array( - $this->options['string_id_col'] => array( - 'Type' => 'text', - 'Value' => $stringID, - 'Key' => true - ), - $this->options['string_page_id_col'] => array( - 'Type' => 'text', - 'Value' => $pageID, - 'Null' => (is_null($pageID) ? true : false) - ), + $fields = array( + $this->options['string_id_col'] => array( + 'Type' => 'text', + 'Value' => $stringID, + 'Key' => true + ), + $this->options['string_page_id_col'] => array( + 'Type' => 'text', + 'Value' => $pageID, + 'Null' => (is_null($pageID) ? true : false) + ), ); foreach ($langs as $langID) { $lang_col = str_replace('%s', $langID, $this->options['string_text_col']); @@ -219,7 +237,7 @@ 'Value' => $stringArray[$langID], ); } - + $res = $this->db->replace($this->options['strings_tables'][$langs[0]], $fields); if (PEAR::isError($res)) { return $res; @@ -231,21 +249,21 @@ $lang_col = $langID; } - $fields = array( - $this->options['string_id_col'] => array( - 'Type' => 'text', - 'Value' => $stringID, - 'Key' => true - ), - $this->options['string_page_id_col'] => array( - 'Type' => 'text', - 'Value' => $pageID, - 'Null' => (is_null($pageID) ? true : false) + $fields = array( + $this->options['string_id_col'] => array( + 'Type' => 'text', + 'Value' => $stringID, + 'Key' => true + ), + $this->options['string_page_id_col'] => array( + 'Type' => 'text', + 'Value' => $pageID, + 'Null' => (is_null($pageID) ? true : false) + ), + $lang_col => array( + 'Type' => 'text', + 'Value' => $stringArray[$langID] ), - $lang_col => array( - 'Type' => 'text', - 'Value' => $stringArray[$langID] - ), ); $res = $this->db->replace($this->options['strings_tables'][$langID], $fields); if (PEAR::isError($res)) { @@ -272,9 +290,24 @@ $langs = $this->getLangs('ids'); $tables = array(); foreach ($langs as $langID) { - $tables[] = $this->options['strings_tables'][$langID]; + if (isset($this->options['strings_tables'][$langID])) { + $tables[] = $this->options['strings_tables'][$langID]; + } else { + $tables[] = $this->options['strings_default_table']; + } + } $tables = array_unique($tables); + //get the tables and remove the non existent ones from the list + $dbTables = $this->_fetchTableNames(); + if (!PEAR::isError($dbTables)) { + foreach ($tables as $k => $table) { + if (!in_array($table, $dbTables)) { + unset($tables[$k]); + } + } + } + foreach ($tables as $table) { $query = 'DELETE FROM '.$table.' WHERE '; $where = array(); http://cvs.php.net/diff.php/pear/Translation2/Admin/Container/mdb2.php?r1=1.5&r2=1.6&ty=u Index: pear/Translation2/Admin/Container/mdb2.php diff -u pear/Translation2/Admin/Container/mdb2.php:1.5 pear/Translation2/Admin/Container/mdb2.php:1.6 --- pear/Translation2/Admin/Container/mdb2.php:1.5 Mon Apr 19 10:55:50 2004 +++ pear/Translation2/Admin/Container/mdb2.php Thu Sep 2 09:26:57 2004 @@ -5,22 +5,22 @@ // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2004 The PHP Group | // +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/3_0.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | +// | This source file is subject to version 3.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/3_0.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: mdb2.php,v 1.5 2004/04/19 14:55:50 quipo Exp $ +// $Id: mdb2.php,v 1.6 2004/09/02 13:26:57 quipo Exp $ // /** * @package Translation2 - * @version $Id: mdb2.php,v 1.5 2004/04/19 14:55:50 quipo Exp $ + * @version $Id: mdb2.php,v 1.6 2004/09/02 13:26:57 quipo Exp $ */ /** @@ -35,7 +35,7 @@ * by the PEAR MDB2 abstraction layer to fetch data. * * @package Translation2 - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ class Translation2_Admin_Container_mdb2 extends Translation2_Container_mdb2 { @@ -44,17 +44,14 @@ // }}} - // {{{ createNewLang() + // {{{ /** - * Creates a new table to store the strings in this language. - * If the table is shared with other langs, it is ALTERed to - * hold strings in this lang too. - * - * @param string $langID - * @return mixed true on success, PEAR_Error on failure + * Fetch the table names from the db + * @access private + * @return mixed array on success, PEAR_Error on failure */ - function createNewLang($langID) + function _fetchTableNames() { $res = $this->query('SHOW TABLES', 'queryAll'); if (PEAR::isError($res)) { @@ -63,16 +60,40 @@ if (empty($res) || !is_array($res)) { //return error } + $tables = array(); + foreach ($res as $record) { + $tables[] = $record[0]; + } + return $tables; + } + + // }}} + // {{{ createNewLang() + + /** + * Creates a new table to store the strings in this language. + * If the table is shared with other langs, it is ALTERed to + * hold strings in this lang too. + * + * @param array $langData + * @return mixed true on success, PEAR_Error on failure + */ + function createNewLang($langData) + { + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; + } - $lang_col = str_replace('%s', $langID, $this->options['string_text_col']); + $lang_col = str_replace('%s', $langData['lang_id'], $this->options['string_text_col']); if (empty($lang_col)) { $lang_col = $this->currentLang['id']; } - if (in_array($this->options['strings_tables'][$langID], $res)) { + if (in_array($langData['table_name'], $tables)) { //table exists - $query = sprintf('ALTER TABLE %s ADD COLUMN %s', - $this->options['strings_tables'][$langID], + $query = sprintf('ALTER TABLE %s ADD COLUMN %s TEXT', + $langData['table_name'], $lang_col ); } else { @@ -84,7 +105,7 @@ .'UNIQUE KEY tablekey (%s, %s), ' .'KEY page_id (%s), ' .'KEY string_id (%s))', - $this->options['strings_tables'][$langID], + $langData['table_name'], $this->options['string_page_id_col'], $this->options['string_id_col'], $lang_col, @@ -104,24 +125,21 @@ * Creates a new entry in the langsAvail table. * If the table doesn't exist yet, it is created. * - * @param array $langData array('lang_id' => 'en', - * 'table_name' => 'i18n', - * 'name' => 'english', - * 'meta' => 'some meta info', - * 'error_text' => 'not available'); + * @param array $langData array('lang_id' => 'en', + * 'table_name' => 'i18n', + * 'name' => 'english', + * 'meta' => 'some meta info', + * 'error_text' => 'not available'); * @return mixed true on success, PEAR_Error on failure */ function addLangToAvailList($langData) { - $res = $this->query('SHOW TABLES', 'queryAll'); - if (PEAR::isError($res)) { - return $res; - } - if (empty($res) || !is_array($res)) { - //return error + $tables = $this->_fetchTableNames(); + if (PEAR::isError($tables)) { + return $tables; } - if (!in_array($this->options['langs_avail_table'], $res)) { + if (!in_array($langData['table_name'], $tables)) { //is this query portable?? $query = sprintf('CREATE TABLE %s (' .'%s CHAR(16), ' @@ -200,17 +218,17 @@ } if ($oneQuery) { - $fields = array( - $this->options['string_id_col'] => array( - 'type' => 'text', - 'value' => $stringID, - 'key' => true - ), - $this->options['string_page_id_col'] => array( - 'type' => 'text', - 'value' => $pageID, - 'null' => (is_null($pageID) ? true : false) - ), + $fields = array( + $this->options['string_id_col'] => array( + 'type' => 'text', + 'value' => $stringID, + 'key' => true + ), + $this->options['string_page_id_col'] => array( + 'type' => 'text', + 'value' => $pageID, + 'null' => (is_null($pageID) ? true : false) + ), ); foreach ($langs as $langID) { $lang_col = str_replace('%s', $langID, $this->options['string_text_col']); @@ -219,7 +237,7 @@ 'value' => $stringArray[$langID], ); } - + $res = $this->db->replace($this->options['strings_tables'][$langs[0]], $fields); if (PEAR::isError($res)) { return $res; @@ -231,21 +249,21 @@ $lang_col = $langID; } - $fields = array( - $this->options['string_id_col'] => array( - 'type' => 'text', - 'value' => $stringID, - 'key' => true - ), - $this->options['string_page_id_col'] => array( - 'type' => 'text', - 'value' => $pageID, - 'null' => (is_null($pageID) ? true : false) + $fields = array( + $this->options['string_id_col'] => array( + 'type' => 'text', + 'value' => $stringID, + 'key' => true + ), + $this->options['string_page_id_col'] => array( + 'type' => 'text', + 'value' => $pageID, + 'null' => (is_null($pageID) ? true : false) + ), + $lang_col => array( + 'type' => 'text', + 'value' => $stringArray[$langID] ), - $lang_col => array( - 'type' => 'text', - 'value' => $stringArray[$langID] - ), ); $res = $this->db->replace($this->options['strings_tables'][$langID], $fields); if (PEAR::isError($res)) { @@ -272,9 +290,24 @@ $langs = $this->getLangs('ids'); $tables = array(); foreach ($langs as $langID) { - $tables[] = $this->options['strings_tables'][$langID]; + if (isset($this->options['strings_tables'][$langID])) { + $tables[] = $this->options['strings_tables'][$langID]; + } else { + $tables[] = $this->options['strings_default_table']; + } + } $tables = array_unique($tables); + //get the tables and remove the non existent ones from the list + $dbTables = $this->_fetchTableNames(); + if (!PEAR::isError($dbTables)) { + foreach ($tables as $k => $table) { + if (!in_array($table, $dbTables)) { + unset($tables[$k]); + } + } + } + foreach ($tables as $table) { $query = 'DELETE FROM '.$table.' WHERE '; $where = array();