From 4508692330e10c2016eb6feba464dc4c766355c4 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 19 Sep 2019 15:26:56 +0900 Subject: [PATCH] Bug fix for translation class, DB IO connection error set fix - The translation file reader did an isset on a set variable insetad of checking if the variable is zero and so never started the translation system - The DB IO connection not set was wrongly set. If the connection failed it is not TRUE and else FALSE. There is a new internal method getConnectionStatus to query this status it returns TRUE/FALSE depending if the connection failed - Update the l10n test page with proper translation tests - init OK - show current lang/file - translation test - switch language test --- .phan/config.php | 1 + 4dev/lang/admin/messages_en_utf8.po | 7 ++++-- 4dev/lang/admin/messages_ja_utf8.po | 7 ++++-- www/admin/l10n_test.php | 20 ++++++++++++++---- www/admin/namespace_test.php | 3 +++ www/configs/config.host.php | 2 ++ www/configs/config.master.php | 5 +++-- www/configs/config.path.php | 10 ++++++--- www/includes/lang/admin/en_utf8.mo | Bin 434 -> 472 bytes www/includes/lang/admin/ja_utf8.mo | Bin 372 -> 841 bytes www/lib/CoreLibs/ACL/Login.php | 2 +- www/lib/CoreLibs/DB/IO.php | 18 +++++++++++----- .../CoreLibs/Language/Core/GetTextReader.php | 2 +- 13 files changed, 57 insertions(+), 20 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 117307ae..352110d7 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -95,6 +95,7 @@ return [ 'www/media', ], 'exclude_file_list' => [ + // ignore all symlink files to edit 'www/admin/edit_access.php', 'www/admin/edit_groups.php', 'www/admin/edit_languages.php', diff --git a/4dev/lang/admin/messages_en_utf8.po b/4dev/lang/admin/messages_en_utf8.po index fbfe06ce..fa3b2d7b 100644 --- a/4dev/lang/admin/messages_en_utf8.po +++ b/4dev/lang/admin/messages_en_utf8.po @@ -1,11 +1,11 @@ -#******************************************************************** +# ******************************************************************** # AUTHOR: Clemens Schwaighofer # CREATED: 2005/08/09 # SHORT DESCRIPTION: # Backned English Messages file for gettext # to craete: msgfmt -o ja.mo messages_en.po # HISTORY: -#********************************************************************/ +# ********************************************************************/ msgid "" msgstr "" @@ -24,3 +24,6 @@ msgstr "Year" msgid "Month" msgstr "Month" + +msgid "INPUT TEST" +msgstr "OUTPUT TEST EN" diff --git a/4dev/lang/admin/messages_ja_utf8.po b/4dev/lang/admin/messages_ja_utf8.po index 6d0ae776..1cf27e48 100644 --- a/4dev/lang/admin/messages_ja_utf8.po +++ b/4dev/lang/admin/messages_ja_utf8.po @@ -1,11 +1,11 @@ -#******************************************************************** +# ******************************************************************** # AUTHOR: Clemens Schwaighofer # CREATED: 2018/03/28 # SHORT DESCRIPTION: # Backend Japanese Messages file for gettext # to craete: msgfmt -o ja.mo messages_ja.po # HISTORY: -#********************************************************************/ +# ********************************************************************/ msgid "" msgstr "" @@ -61,3 +61,6 @@ msgstr "土" msgid "Sun" msgstr "日" + +msgid "INPUT TEST" +msgstr "OUTPUT TEST JA" diff --git a/www/admin/l10n_test.php b/www/admin/l10n_test.php index 8ad1a7cf..014d66b7 100755 --- a/www/admin/l10n_test.php +++ b/www/admin/l10n_test.php @@ -5,13 +5,25 @@ // namespace test ob_start(); +// init language $lang = 'en_utf8'; - // admin class tests require 'config.php'; $l = new CoreLibs\Language\L10n($lang); - -echo "OK
"; - ob_end_flush(); + +$string = 'INPUT TEST'; + +echo "LANGUAGE SET: ".$l->__getLang()."
"; +echo "LANGUAGE FILE: ".$l->__getMoFile()."
"; +echo "INPUT TEST: ".$string." => ".$l->__($string)."
"; + +// switch to other language +$lang = 'ja_utf8'; +$l->l10nReloadMOfile($lang); + +echo "LANGUAGE SET: ".$l->__getLang()."
"; +echo "LANGUAGE FILE: ".$l->__getMoFile()."
"; +echo "INPUT TEST: ".$string." => ".$l->__($string)."
"; + // __END__ diff --git a/www/admin/namespace_test.php b/www/admin/namespace_test.php index 009ac21d..e8248c92 100755 --- a/www/admin/namespace_test.php +++ b/www/admin/namespace_test.php @@ -17,6 +17,9 @@ echo "DIR: ".DIR."
ROOT: ".ROOT."
BASE: ".BASE."
"; $lang = 'ja_utf8'; $base = new CoreLibs\Admin\Backend(DB_CONFIG, $lang); ob_end_flush(); +if ($base->getConnectionStatus()) { + die("Cannot connect to database"); +} print "Start time: ".$base->runningTime()."
"; print "ByteStringFormat: ".$base->ByteStringFormat(1234567.12)."
"; diff --git a/www/configs/config.host.php b/www/configs/config.host.php index 5347620f..1c5eadff 100755 --- a/www/configs/config.host.php +++ b/www/configs/config.host.php @@ -27,6 +27,8 @@ $SITE_CONFIG = array ( 'debug_flag' => true, // site language 'site_lang' => 'en_utf8', + // enable/disable login override + 'login_enabled' => true ) ); diff --git a/www/configs/config.master.php b/www/configs/config.master.php index 913bc3d6..a431185e 100644 --- a/www/configs/config.master.php +++ b/www/configs/config.master.php @@ -145,7 +145,7 @@ DEFINE('DEFAULT_ENCODING', 'UTF-8'); // below two can be defined here, but they should be // defined in either the header file or the file itself /************* LOGGING *******************/ -// DEFINE('LOG_FILE_ID', ''); +DEFINE('LOG_FILE_ID', ''); /************* CLASS ERRORS *******************/ // 0 = default all OFF @@ -220,7 +220,7 @@ if ((array_key_exists('HTTPS', $_SERVER) && !empty($_SERVER['HTTPS']) && $_SERVE } // define the db config set name, the db config and the db schema DEFINE('DB_CONFIG_NAME', $SITE_CONFIG[$HOST_NAME]['db_host']); -DEFINE('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME]); +DEFINE('DB_CONFIG', isset($DB_CONFIG[DB_CONFIG_NAME]) ? $DB_CONFIG[DB_CONFIG_NAME] : array ()); // DEFINE('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']); // DEFINE('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']); // override for login and global schemas @@ -230,6 +230,7 @@ DEFINE('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME]); DEFINE('TARGET', $SITE_CONFIG[$HOST_NAME]['location']); DEFINE('DEBUG', $SITE_CONFIG[$HOST_NAME]['debug_flag']); DEFINE('SITE_LANG', $SITE_CONFIG[$HOST_NAME]['site_lang']); +DEFINE('LOGIN_ENABLED', $SITE_CONFIG[$HOST_NAME]['login_enabled']); // paths // DEFINE('CSV_PATH', $PATHS[TARGET]['csv_path']); // DEFINE('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']); diff --git a/www/configs/config.path.php b/www/configs/config.path.php index 6bd569f9..c77a158e 100755 --- a/www/configs/config.path.php +++ b/www/configs/config.path.php @@ -10,8 +10,12 @@ // File and Folder paths // ID is TARGET (first array element) -// $PATHS['test']['csv_path'] = ''; -// $PATHS['test']['perl_bin'] = ''; -// $PATHS['test']['redirect_url'] = ''; +/*$PATHS = array ( + 'test' => array ( + 'csv_path' => '', + 'perl_bin' => '', + 'other_url' => '', + ) +)*/ // __END__ diff --git a/www/includes/lang/admin/en_utf8.mo b/www/includes/lang/admin/en_utf8.mo index 90d607fd31d2f3afafed41bc7e343221b41e4c71..ce0b0578005ff5478879329155db4f37d58503c9 100644 GIT binary patch delta 256 zcmdnQe1p0Eo)F7a1|VPoVi_Q|0b*7ljsap2C;(zEAT9)Aka!IcgVZ(wu^A%+LpzY> z1LA!^Hc0*~kOs+L2GT$TW&3Xfe364kYZp05kN4p+TEhqp(M4iG&3hrFF9W?tAH!OKSbBLC^fMpGe1w)C9x#c zO2Np$z*N`3Lf61j!NAhW$V}V7(!gNiBQM1eh)xBs#Dc^;1)I#gw0u<4CMPn+a{K1z Nm1HnPrY06K004C{ECB!j diff --git a/www/includes/lang/admin/ja_utf8.mo b/www/includes/lang/admin/ja_utf8.mo index 7be9274bfd95966501d1c83e467a8f735c70709f..67fd6ed966b090b2c7926d7eda4e2d9e8558c6ae 100644 GIT binary patch literal 841 zcmY+A&ubGw6vtn+^~d@X5%kc*oRx_`4yCMGOp~qI;$}m#QR;2nOgCGSnPqp@GzSk6 zsk!zbDg*?fpopkY550Ks5AjkG@lWs|_$Ev#KK47Gd2eUly!U=yn0*Oo=TY;h5$clO z&)|Z#i9Cwz8$LzOqCY@d$SveCi9*&%ZBsFlNcw)zhYQ0ylJ>#Xd5mebwA5Ud>W3UbY16A z+AutwmENB~okpEP={wqV@4D{;JA)fthc-PgZMtqKvp%e(F;rxpf?KUM0}?om0K8b_ zii0PGmTE&)LW3!2|q4JG{$9R>;D3kHt}2uJiORkCINF^?HR+cCDIE>-y?U`$aZ3$S@;$Fv zbxXy-^{WlC$`U5X?O3eK!bbAn^GlZJdd^{2HwxFS63&DRe5{{fHHvSlYe|R2;uZ

^mck_GI|fc1|MPaWf#VKyRbj_j3?k91E08d delta 164 zcmX@f_Jzsfo)F7a1|VPrVi_P-0b*t#)&XJ=umEB!prj>`2C0F8$p;y2EQ%dUQVUBn za}xEE^YyX{xB~n`be)S*6H7Al^K@MjOH!>Aj0_A+bPX(Z4b2n`O{|Q}wGAu{3?|Dm cc`1fKv?_Qd79{2=*ktCV<)a!mc@9%70A2wlTmS$7 diff --git a/www/lib/CoreLibs/ACL/Login.php b/www/lib/CoreLibs/ACL/Login.php index ba747966..255de0a0 100644 --- a/www/lib/CoreLibs/ACL/Login.php +++ b/www/lib/CoreLibs/ACL/Login.php @@ -122,7 +122,7 @@ class Login extends \CoreLibs\DB\IO // create db connection and init base class parent::__construct($db_config, $set_control_flag); - if ($this->db_init_error === false) { + if ($this->db_init_error === true) { echo 'Could not connect to DB
'; // if I can't connect to the DB to auth exit hard. No access allowed exit; diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index dda77af1..01e58a2c 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -376,18 +376,15 @@ class IO extends \CoreLibs\Basic // abort error $this->error_id = 10; $this->__dbError(); - $this->db_init_error = false; + $this->db_init_error = true; } // connect to DB if (!$this->__connectToDB()) { $this->error_id = 16; $this->__dbError(); - $this->db_init_error = false; + $this->db_init_error = true; } - - // so we can check that we have a successful DB connection created - $this->db_init_error = true; } /** @@ -897,6 +894,17 @@ class IO extends \CoreLibs\Basic } } + /** + * returns the db init error + * if failed to connect it is set to true + * else false + * @return bool connection failure status + */ + public function getConnectionStatus(): bool + { + return $this->db_init_error; + } + /** * sets new db schema * @param string $db_schema schema name, if not given tries internal default db schema diff --git a/www/lib/CoreLibs/Language/Core/GetTextReader.php b/www/lib/CoreLibs/Language/Core/GetTextReader.php index 776c7309..cdf84ed5 100755 --- a/www/lib/CoreLibs/Language/Core/GetTextReader.php +++ b/www/lib/CoreLibs/Language/Core/GetTextReader.php @@ -106,7 +106,7 @@ class GetTextReader public function __construct($Reader, $enable_cache = true) { // If there isn't a StreamReader, turn on short circuit mode. - if (!$Reader || isset($Reader->error)) { + if (!$Reader || $Reader->error) { $this->short_circuit = true; return; }