From 372bb33909a722829f71323474144aee36c11255 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 20 Dec 2017 12:34:04 +0100 Subject: [PATCH] Refactor --- debian/changelog | 2 +- forms/admin/photos/ui.xml | 2 +- forms/cms/home/ui.xml | 9 ++------- forms/cms/training/ui.xml | 6 +++--- forms/news/new/new.js | 2 +- forms/news/new/ui.xml | 2 +- forms/news/news/ui.xml | 4 ++-- js/hedera/gui.js | 11 ++++++++--- js/hedera/tpv.js | 6 +++--- js/htk/field/image.js | 2 +- package.json | 2 +- rest/core/query.php | 16 ++++++++-------- rest/image/resize.php | 18 +++++++++--------- rest/image/thumb.php | 4 ++-- rest/image/upload.php | 2 +- rest/image/util.php | 6 +++--- rest/misc/contact.php | 18 +++++++++--------- rest/misc/production.php | 2 +- rest/tpv/confirm-mail.php | 22 +++++++++++----------- rest/tpv/confirm-soap.php | 2 +- utils/extract-locale.js | 33 ++++++++++++++++----------------- web/mailer.php | 6 +++--- 22 files changed, 88 insertions(+), 89 deletions(-) diff --git a/debian/changelog b/debian/changelog index b819afc7..ffa34278 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.405.54) stable; urgency=low +hedera-web (1.405.55) stable; urgency=low * Initial Release. diff --git a/forms/admin/photos/ui.xml b/forms/admin/photos/ui.xml index a0a8ee1b..259aadfd 100644 --- a/forms/admin/photos/ui.xml +++ b/forms/admin/photos/ui.xml @@ -9,7 +9,7 @@ - SELECT name, `desc` FROM image_schema ORDER BY `desc` + SELECT name, `desc` FROM imageCollection ORDER BY `desc` diff --git a/forms/cms/home/ui.xml b/forms/cms/home/ui.xml index 8fa004a0..bae37fcd 100644 --- a/forms/cms/home/ui.xml +++ b/forms/cms/home/ui.xml @@ -14,9 +14,9 @@ - SELECT title, date_time, text, image, id FROM news + SELECT title, text, image, id FROM news WHERE tag != 'course' - ORDER BY priority, date_time DESC + ORDER BY priority, created DESC @@ -24,11 +24,6 @@

-
diff --git a/forms/cms/training/ui.xml b/forms/cms/training/ui.xml index 86efa1c7..969c3c17 100644 --- a/forms/cms/training/ui.xml +++ b/forms/cms/training/ui.xml @@ -7,9 +7,9 @@ - SELECT title, date_time, text, image, id FROM news + SELECT title, created, text, image, id FROM news WHERE tag = 'course' - ORDER BY priority, date_time DESC + ORDER BY priority, created DESC @@ -18,7 +18,7 @@

- +

diff --git a/forms/news/new/new.js b/forms/news/new/new.js index fd30aeb3..9a2b1099 100644 --- a/forms/news/new/new.js +++ b/forms/news/new/new.js @@ -11,7 +11,7 @@ Hedera.New = new Class ,activate: function () { this.$('model').mode = Db.Model.Mode.ON_DEMAND; - this.$('model').setDefault ('user_id', 'news', + this.$('model').setDefault ('userFk', 'news', new Sql.Function ({schema: 'account', name: 'userGetId'})); tinymce.init ({ diff --git a/forms/news/new/ui.xml b/forms/news/new/ui.xml index 9d66e02b..8ee6ecc9 100644 --- a/forms/news/new/ui.xml +++ b/forms/news/new/ui.xml @@ -46,7 +46,7 @@ - SELECT name, description FROM news_tag + SELECT name, description FROM newsTag ORDER BY description diff --git a/forms/news/news/ui.xml b/forms/news/news/ui.xml index 46e6342f..ecdc8d6a 100644 --- a/forms/news/news/ui.xml +++ b/forms/news/news/ui.xml @@ -15,8 +15,8 @@ SELECT n.id, u.nickname, priority, image, title FROM news n - JOIN account.user u ON u.id = n.user_id - ORDER BY priority, n.date_time DESC + JOIN account.user u ON u.id = n.userFk + ORDER BY priority, n.created DESC diff --git a/js/hedera/gui.js b/js/hedera/gui.js index 63da43f5..f1489792 100644 --- a/js/hedera/gui.js +++ b/js/hedera/gui.js @@ -56,7 +56,8 @@ module.exports = new Class this.$('social-bar').conn = this._conn; var sql = 'SELECT nickname FROM account.userView;' - +'SELECT default_form, image_dir, image_host FROM config;' + +'SELECT default_form, image_host FROM config;' + +'SELECT url FROM imageConfig;' +'SELECT production_domain, test_domain FROM config;'; this._conn.execQuery (sql, this.onMainQueryDone.bind (this)); @@ -147,6 +148,10 @@ module.exports = new Class // Retrieving configuration parameters + Vn.Config.imageUrl = resultSet.fetchValue (); + + // Retrieving configuration parameters + var res = resultSet.fetchResult (); if (res.next () && res.get ('test_domain')) @@ -175,7 +180,7 @@ module.exports = new Class ,loadMenu: function () { - var sql = 'CALL formList ()'; + var sql = 'SELECT * FROM myMenu'; this._conn.execQuery (sql, this._onMenuLoad.bind (this)); } @@ -189,7 +194,7 @@ module.exports = new Class if (res) for (var i = 0; res.next (); i++) { - var parent = res.get ('parent'); + var parent = res.get ('parentFk'); if (!sectionMap[parent]) sectionMap[parent] = []; diff --git a/js/hedera/tpv.js b/js/hedera/tpv.js index ffdf6495..717e041b 100644 --- a/js/hedera/tpv.js +++ b/js/hedera/tpv.js @@ -81,9 +81,9 @@ module.exports = new Class var batch = new Sql.Batch (); batch.addValue ('transaction', parseInt (this.tpvOrder)); - var query = 'SELECT t.amount, m.company_id ' + var query = 'SELECT t.amount, m.companyFk ' +'FROM tpv_transaction_view t ' - +'JOIN tpv_merchant m ON t.merchant_id = m.id ' + +'JOIN tpvMerchant m ON m.id = t.merchant_id ' +'WHERE t.id = #transaction'; this.conn.execQuery (query, this._onRetryPayDone.bind (this), batch); @@ -94,7 +94,7 @@ module.exports = new Class var res = resultSet.fetchResult (); if (res.next ()) - this._realPay (res.get ('amount'), res.get ('company_id')); + this._realPay (res.get ('amount'), res.get ('companyFk')); else Htk.Toast.showError (_('AmountError')); } diff --git a/js/htk/field/image.js b/js/htk/field/image.js index 20b8c3f0..94dc3543 100644 --- a/js/htk/field/image.js +++ b/js/htk/field/image.js @@ -131,7 +131,7 @@ module.exports = new Class ,_makeSrc: function (subdir) { - var src = Vn.Config['image_dir'] +'/'; + var src = Vn.Config.imageUrl +'/'; if (this._directory) src += this._directory +'/'; diff --git a/package.json b/package.json index aa1707c5..f381da7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hedera-web", - "version": "1.405.54", + "version": "1.405.55", "description": "Verdnatura web page", "license": "GPL-3.0", "repository": { diff --git a/rest/core/query.php b/rest/core/query.php index 1e3243c1..cce67e9b 100644 --- a/rest/core/query.php +++ b/rest/core/query.php @@ -34,16 +34,16 @@ class Query extends Vn\Web\JsonRequest if ($db->checkWarnings () && ($result = $db->query ('SHOW WARNINGS'))) { - $sql = 'SELECT description, @warn code '. - 'FROM sql_message WHERE code = @warn'; + $sql = 'SELECT `description`, @warn `code` + FROM `message` WHERE `code` = @warn'; - while ($row = $result->fetch_assoc ()) + while ($row = $result->fetch_object ()) { - if ($row['Code'] == 1265 - && ($warning = $db->getRow ($sql))) - trigger_error ("{$warning['code']}: {$warning['description']}", E_USER_WARNING); + if ($row->Code == 1265 + && ($warning = $db->getObject ($sql))) + trigger_error ("{$warning->code}: {$warning->description}", E_USER_WARNING); else - trigger_error ("{$row['Code']}: {$row['Message']}", E_USER_WARNING); + trigger_error ("{$row->Code}: {$row->Message}", E_USER_WARNING); } } @@ -56,7 +56,7 @@ class Query extends Vn\Web\JsonRequest if ($e->getCode () == 1644) { $dbMessage = $e->getMessage (); - $sql = 'SELECT description FROM sql_message WHERE code = #'; + $sql = 'SELECT `description` FROM `message` WHERE `code` = #'; $message = $db->getValue ($sql, [$dbMessage]); if ($message) diff --git a/rest/image/resize.php b/rest/image/resize.php index 71ca0df0..2f7f4940 100644 --- a/rest/image/resize.php +++ b/rest/image/resize.php @@ -14,10 +14,10 @@ require_once (__DIR__.'/lib.php'); class Resize extends Vn\Lib\Method { const PARAMS = [ - 'src_dir' - ,'dst_dir' - ,'max_height' - ,'max_Width' + 'srcDir' + ,'dstDir' + ,'maxHeight' + ,'maxWidth' ,'rewrite' ,'crop' ,'symbolic' @@ -28,13 +28,13 @@ class Resize extends Vn\Lib\Method $options = getopt ('', $params); - if (!$this->checkParams ($options, self::PARAMS) + if (!$this->checkParams ($options, self::PARAMS)) $this->usage (); - $srcDir = $options['src_dir']; - $dstDir = $options['dst_dir']; - $maxHeight = $options['max_height']; - $maxWidth = $options['max_Width']; + $srcDir = $options['srcDir']; + $dstDir = $options['dstDir']; + $maxHeight = $options['maxHeight']; + $maxWidth = $options['maxWidth']; $rewrite = isset ($options['rewrite']); $crop = isset ($options['crop']); $symbolic = isset ($options['symbolic']); diff --git a/rest/image/thumb.php b/rest/image/thumb.php index 77db5872..29416e94 100644 --- a/rest/image/thumb.php +++ b/rest/image/thumb.php @@ -52,8 +52,8 @@ class Thumb extends Vn\Web\RestRequest $row = $db->getValue ( 'SELECT crop - FROM image_schema s - JOIN image_schema_size z ON z.image_schema_id = s.id + FROM imageCollection s + JOIN imageCollectionSize z ON z.collectionFk = s.id WHERE s.name = #schema AND z.width = #width AND z.height = #height' diff --git a/rest/image/upload.php b/rest/image/upload.php index 6f81ec07..5f76cde3 100644 --- a/rest/image/upload.php +++ b/rest/image/upload.php @@ -86,7 +86,7 @@ class Upload extends Vn\Web\JsonRequest $symbolicSrc = "../full/$fileName"; $image = Image::create ($tmpName); - Image::resizeSave ($image, $fullFile, $info['max_height'], $info['max_width']); + Image::resizeSave ($image, $fullFile, $info['maxHeight'], $info['maxWidth']); foreach ($info['sizes'] as $size => $i) { diff --git a/rest/image/util.php b/rest/image/util.php index 3236bdd4..5a3cd615 100644 --- a/rest/image/util.php +++ b/rest/image/util.php @@ -26,8 +26,8 @@ class Util $db = $this->app->getSysConn (); $info = $db->getRow ( - 'SELECT id, max_width, max_height, `schema`, `table`, `column` - FROM image_schema WHERE name = #schema' + 'SELECT id, maxWidth, maxHeight, `schema`, `table`, `column` + FROM imageCollection WHERE name = #schema' ,['schema' => $schema] ); @@ -36,7 +36,7 @@ class Util $res = $db->query ( 'SELECT width, height, crop - FROM image_schema_size WHERE image_schema_id = #id' + FROM imageCollectionSize WHERE collectionFk = #id' ,['id' => $info['id']] ); diff --git a/rest/misc/contact.php b/rest/misc/contact.php index 87109b3b..15d8a87a 100644 --- a/rest/misc/contact.php +++ b/rest/misc/contact.php @@ -31,32 +31,32 @@ class Contact extends Vn\Web\JsonRequest //$db->queryFromFile (__DIR__.'/contact', $_REQUEST); //$customerId = $db->getValue ('SELECT @id'); - $conf = $db->getRow ( + $conf = $db->getObject ( 'SELECT m.host, m.port, m.secure, m.sender, m.user, m.password, c.recipient - FROM mail_config m JOIN contact c' + FROM mailConfig m JOIN contact c' ); $mail = new PHPMailer (); $mail->isSMTP (); - $mail->Host = $conf['host']; + $mail->Host = $conf->host; - if (!empty ($conf['user'])) + if (!empty ($conf->user)) { $mail->SMTPAuth = TRUE; - $mail->Username = $conf['user']; - $mail->Password = base64_decode ($conf['password']); + $mail->Username = $conf->user; + $mail->Password = base64_decode ($conf->password); } else $mail->SMTPAuth = FALSE; - if ($conf['secure']) + if ($conf->secure) { $mail->SMTPSecure = 'ssl'; $mail->Port = 465; } - $mail->setFrom ($conf['sender'], 'Web'); - $mail->addAddress ($conf['recipient']); + $mail->setFrom ($conf->sender, 'Web'); + $mail->addAddress ($conf->recipient); $mail->isHTML (TRUE); $mail->Subject = s('New customer request'); $mail->Body = '
'. print_r ($_REQUEST, TRUE) .'
'; diff --git a/rest/misc/production.php b/rest/misc/production.php index 18bf548d..62ee72b4 100644 --- a/rest/misc/production.php +++ b/rest/misc/production.php @@ -7,7 +7,7 @@ class Production extends Vn\Web\JsonRequest function run ($db) { $row = $db->getObject ( - 'SELECT displayText FROM production WHERE deviceId = #', + 'SELECT displayText FROM vn.routeGate WHERE deviceId = #', [$_REQUEST['deviceId']] ); diff --git a/rest/tpv/confirm-mail.php b/rest/tpv/confirm-mail.php index be71416c..6c12a38c 100644 --- a/rest/tpv/confirm-mail.php +++ b/rest/tpv/confirm-mail.php @@ -10,17 +10,17 @@ class ConfirmMail extends Vn\Lib\Method function run ($db) { $imap = NULL; - $imapConf = $db->getRow ( - 'SELECT host, user, pass, clean_period, success_folder, error_folder - FROM tpv_imap_config' + $imapConf = $db->getObject ( + 'SELECT host, user, pass, cleanPeriod, successFolder, errorFolder + FROM tpvImapConfig' ); $mailbox = sprintf ('{%s/imap/ssl/novalidate-cert}', - $imapConf['host']); + $imapConf->host); $imap = imap_open ($mailbox - ,$imapConf['user'] - ,base64_decode ($imapConf['pass']) + ,$imapConf->user + ,base64_decode ($imapConf->pass) ); if (!$imap) @@ -61,9 +61,9 @@ class ConfirmMail extends Vn\Lib\Method // Moves the processed mail to another folder if ($success) - $folder = $imapConf['success_folder']; + $folder = $imapConf->successFolder; else - $folder = $imapConf['error_folder']; + $folder = $imapConf->errorFolder; if (!imap_mail_move ($imap, $msg, "$folder")) trigger_error (imap_last_error (), E_USER_WARNING); @@ -80,12 +80,12 @@ class ConfirmMail extends Vn\Lib\Method if (rand (1, 20) == 1) { $folders = array ( - $imapConf['success_folder'] - ,$imapConf['error_folder'] + $imapConf->successFolder + ,$imapConf->errorFolder ); $date = new \DateTime (NULL); - $date->sub (new \DateInterval ($imapConf['clean_period'])); + $date->sub (new \DateInterval ($imapConf->cleanPeriod)); $filter = sprintf ('BEFORE "%s"', $date->format('D, j M Y')); foreach ($folders as $folder) diff --git a/rest/tpv/confirm-soap.php b/rest/tpv/confirm-soap.php index 86a3b9c6..55d25a05 100644 --- a/rest/tpv/confirm-soap.php +++ b/rest/tpv/confirm-soap.php @@ -50,7 +50,7 @@ function procesaNotificacionSIS ($XML) $shaString = substr ($requestString, $start, $end - $start + 10); $key = $db->getValue ( - 'SELECT secret_key FROM tpv_merchant WHERE id = #' + 'SELECT secretKey FROM tpvMerchant WHERE id = #' ,[$params['Ds_MerchantCode']] ); diff --git a/utils/extract-locale.js b/utils/extract-locale.js index d6cac973..620f900b 100644 --- a/utils/extract-locale.js +++ b/utils/extract-locale.js @@ -12,7 +12,7 @@ if (lang == null) process.exit(1); } -let nDirs; +let nTasks; let projectDir; fs.remove(lang, () => { @@ -21,8 +21,6 @@ fs.remove(lang, () => { let len = projectDir.length + 1; glob(`${projectDir}/**/locale/`, (err, localeDirs) => { - nDirs = localeDirs.length * 2; - for (let localeDir of localeDirs) { localeDir = localeDir.substr(len) @@ -31,7 +29,9 @@ fs.remove(lang, () => { exportLocale(localeDir); } - }) + + nTasks = localeDirs.length; + }); }); }); @@ -40,7 +40,8 @@ function exportLocale (localeDir) { fs.mkdirp(dstDir, err => { if (err) { - onError(err); + console.log(err); + onTaskEnd(); return; } @@ -48,28 +49,26 @@ function exportLocale (localeDir) { src = `${projectDir}/${localeDir}/en.json`; dst = `${dstDir}/en.json`; - fs.copy(src, dst, onDirEnd); + fs.copy(src, dst, onTaskEnd); src = `${projectDir}/${localeDir}/${lang}.json`; dst = `${dstDir}/${lang}.json`; - fs.copy(src, dst, onDirEnd); - }); -} + fs.copy(src, dst, onTaskEnd); -function onError (err) { - console.log(err); - onDirEnd(); + nTasks += 2; + onTaskEnd(); + }); } let output; let archive; -function onDirEnd() { - nDirs--; - if (nDirs > 0) return; +function onTaskEnd() { + nTasks--; + if (nTasks > 0) return; output = fs.createWriteStream(`${lang}.zip`); - output.on ('close', onArchiveEnd); + output.on ('close', onArchiveClose); archive = archiver('zip', { zlib: { level: 9 } @@ -82,7 +81,7 @@ function onDirEnd() { archive.finalize(); } -function onArchiveEnd() { +function onArchiveClose() { fs.remove(lang); console.log ('Export finalized!'); } diff --git a/web/mailer.php b/web/mailer.php index 0b6b5f20..aeaba74c 100644 --- a/web/mailer.php +++ b/web/mailer.php @@ -13,8 +13,8 @@ class Mailer function __construct ($db) { $this->conf = $db->getObject ( - 'SELECT host, port, secure, sender, sender_name, user, password - FROM hedera.mail_config' + 'SELECT host, port, secure, sender, senderName, user, password + FROM hedera.mailConfig' ); } @@ -41,7 +41,7 @@ class Mailer $mail->Port = 465; } - $mail->setFrom ($conf->sender, $conf->sender_name); + $mail->setFrom ($conf->sender, $conf->senderName); $mail->IsHTML (TRUE); $mail->Subject = $subject; $mail->Body = $body;