From 466363062e34b57291dbe47fdee8f1b4320aa682 Mon Sep 17 00:00:00 2001 From: Vladimir Schneider Date: Wed, 25 Mar 2015 17:10:32 -0400 Subject: [PATCH] translations cleanup, fix reminderss.email --- scripts/translation-stats.sql | 104 ++++++++++++++++++ scripts/translations-manager.sql | 8 ++ .../TranslationManager/Controller.php | 8 ++ 3 files changed, 120 insertions(+) diff --git a/scripts/translation-stats.sql b/scripts/translation-stats.sql index eea2706..c07ef95 100644 --- a/scripts/translation-stats.sql +++ b/scripts/translation-stats.sql @@ -82,6 +82,7 @@ GROUP BY `group`, `key` ; # this query gives a list of mismatched translations +# 3 SELECT DISTINCT lt.`group`, lt.id, ft.* FROM ltm_translations lt JOIN @@ -105,6 +106,109 @@ FROM ltm_translations lt ON (lt.locale = 'ru' AND lt.value LIKE BINARY ft.ru) AND lt.`key` = ft.key ORDER BY `key`, `group` ; + +# TODO: implement pivot and have it maintained, either with triggers or in php +# same as above but with temp tables, no benefit, however with a pivot table it is 3x faster but pivot needs to be maintained +# and updated. However if for every key, group change a single row is deleted and inserted with updates then +# the impact is spread to the changes while the benefits are accrued for every page refresh. + +# 2 +# DROP TABLE IF EXISTS ltm_trans_pivot; +# CREATE TABLE ltm_trans_pivot AS +TRUNCATE ltm_trans_pivot; +INSERT INTO ltm_trans_pivot +SELECT lt.`group`, lt.`key`, group_concat(CASE lt.locale WHEN 'en' THEN VALUE ELSE NULL END) en, group_concat(CASE lt.locale WHEN 'ru' THEN VALUE ELSE NULL END) ru +FROM (SELECT value, `group`, `key`, locale FROM ltm_translations + UNION ALL + SELECT NULL, `group`, `key`, locale FROM ((SELECT DISTINCT locale FROM ltm_translations) lc + CROSS JOIN (SELECT DISTINCT `group`, `key` FROM ltm_translations) lg) + ) lt +GROUP BY `group`, `key`; + +# DROP TEMPORARY TABLE IF EXISTS ltm_trans_pivot2; +# CREATE TEMPORARY TABLE ltm_trans_pivot2 AS +# SELECT * FROM ltm_trans_pivot; + +# 3a +SELECT DISTINCT lt.`group`, lt.id, ft.* +FROM ltm_translations lt + JOIN + (SELECT DISTINCT mt.`key`, mt.ru ru, mt.en en + FROM ltm_trans_pivot mt + JOIN ltm_trans_pivot ht ON mt.`key` = ht.`key` + WHERE (mt.ru not like binary ht.ru AND mt.en like binary ht.en) or (mt.ru like binary ht.ru AND mt.en not like binary ht.en) + ) ft + ON (lt.locale = 'ru' AND lt.value LIKE BINARY ft.ru) AND lt.`key` = ft.key +ORDER BY `key`, `group` +; + + + + + + + + + + + + + + + + +# 1 +SELECT NULL, `group`, `key`, locale FROM ((SELECT DISTINCT locale FROM ltm_translations) lc + CROSS JOIN (SELECT DISTINCT `group`, `key` FROM ltm_translations) lg); + +DROP TEMPORARY TABLE IF EXISTS ltm_locales; +CREATE TEMPORARY TABLE ltm_locales AS + SELECT DISTINCT locale FROM ltm_translations; + +DROP TEMPORARY TABLE IF EXISTS ltm_groups_keys; +CREATE TEMPORARY TABLE ltm_groups_keys AS + SELECT DISTINCT `group`, `key` FROM ltm_translations; + +# 1a +SELECT NULL, `group`, `key`, locale FROM ltm_locales lc + CROSS JOIN ltm_groups_keys lg; + +#2a +SELECT lt.`group`, lt.`key`, group_concat(CASE lt.locale WHEN 'en' THEN VALUE ELSE NULL END) en, group_concat(CASE lt.locale WHEN 'ru' THEN VALUE ELSE NULL END) ru +FROM (SELECT value, `group`, `key`, locale FROM ltm_translations + UNION ALL + SELECT NULL, `group`, `key`, locale FROM ltm_locales lc + CROSS JOIN ltm_groups_keys lg + ) lt +GROUP BY `group`, `key`; + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT DISTINCT mt.`key`, BINARY mt.ru ru, BINARY mt.en en FROM (SELECT lt.`group`, lt.`key`, group_concat(CASE lt.locale WHEN 'en' THEN VALUE ELSE NULL END) en, group_concat(CASE lt.locale WHEN 'ru' THEN VALUE ELSE NULL END) ru diff --git a/scripts/translations-manager.sql b/scripts/translations-manager.sql index ef8e52b..e640939 100644 --- a/scripts/translations-manager.sql +++ b/scripts/translations-manager.sql @@ -162,4 +162,12 @@ INSERT INTO ltm_translations WHERE NOT exists(SELECT * FROM ltm_translations tr WHERE tr.`key` = kt.`key` AND tr.`group` = kt.`group` AND tr.locale = lt.locale); +# select missing page-titles and add them +# create, delete, edit, show +INSERT INTO ltm_translations (status, locale, `group`, `key`, value, created_at, updated_at, source, saved_value) + SELECT DISTINCT 1 status, locale, 'page-titles' `group`, `key`, `value`, sysdate() created_at, sysdate() updated_at, NULL `source`, NULL saved_value + FROM ltm_translations lt + WHERE (`key` LIKE 'create-%' OR `key` LIKE 'delete-%' OR `key` LIKE 'edit-%' OR `key` LIKE 'show-%' OR `key` LIKE 'index-%') AND `group` NOT IN ('messages', 'validation', 'reminders', 'translations') + AND NOT exists(SELECT * FROM ltm_translations pt WHERE pt.`key` = lt.`key` AND pt.`group` = 'page-titles'); +; diff --git a/src/Barryvdh/TranslationManager/Controller.php b/src/Barryvdh/TranslationManager/Controller.php index 3968e1b..0c2bedc 100644 --- a/src/Barryvdh/TranslationManager/Controller.php +++ b/src/Barryvdh/TranslationManager/Controller.php @@ -415,6 +415,14 @@ function postFind() return Response::json(array('status' => 'ok', 'counter' => (int)$numFound)); } + public + function postDeleteAll() + { + $numFound = $this->manager->truncateTranslations(); + + return Response::json(array('status' => 'ok', 'counter' => (int)$numFound)); + } + public function postPublish($group) {