Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
* Minor bug fixes
  • Loading branch information
sakgiok committed Aug 18, 2019
1 parent 6ec5380 commit fff30ce
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 22 deletions.
4 changes: 3 additions & 1 deletion sakgiok_latinurls changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
## v1.0.0
* Initial release.
* Initial release.
## v1.0.1
* Minor bug fixes.
2 changes: 1 addition & 1 deletion sakgiok_latinurls/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>codwfeeplus</name>
<displayName><![CDATA[Latin Product URLs]]></displayName>
<version><![CDATA[1.0.0]]></version>
<version><![CDATA[1.0.1]]></version>
<description><![CDATA[Converts non latin product urls to latin.]]></description>
<author><![CDATA[Sakis Gkiokas]]></author>
<is_configurable>1</is_configurable>
Expand Down
114 changes: 94 additions & 20 deletions sakgiok_latinurls/sakgiok_latinurls.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class sakgiok_latinurls extends Module
{

private $_showclearbutton = false;
private $def_exec_time = 10;
private $def_exec_time = 25;
private $use_exec_time = false;
private $_html = '';
private $_msg = array();
private $_warnings = array();
Expand Down Expand Up @@ -56,6 +57,9 @@ class sakgiok_latinurls extends Module
array('name' => 'SG_LATINURLS_AUTO_UPDATE', 'type' => 'Int', 'out' => 'auto update', 'multilang' => 0, 'req' => 0),
array('name' => 'SG_LATINURLS_CHARS_INDEX', 'type' => 'Int', 'out' => 'char file index', 'multilang' => 0, 'req' => 0),
array('name' => 'SG_LATINURLS_AUTOCONVERT', 'type' => 'Int', 'out' => 'auto convert', 'multilang' => 0, 'req' => 0),
array('name' => 'SG_LATINURLS_USEEXECTIME', 'type' => 'Int', 'out' => 'use max_exec_time', 'multilang' => 0, 'req' => 0),
array('name' => 'SG_LATINURLS_DEFEXECTIME', 'type' => 'Int', 'out' => 'default max_exec_time value', 'multilang' => 0, 'req' => 0),
array('name' => 'SG_LATINURLS_BATCHSIZE', 'type' => 'Int', 'out' => 'default max_exec_time value', 'multilang' => 0, 'req' => 0),
);
protected $_pagination = array(20, 50, 100, 300, 1000);
protected $_default_pagination = 50;
Expand All @@ -67,7 +71,7 @@ public function __construct()
$this->is17 = true;
}
$this->name = 'sakgiok_latinurls';
$this->version = '1.0.0';
$this->version = '1.0.1';
$this->author = 'Sakis Gkiokas';
$this->need_instance = 1;
$this->is_eu_compatible = 1;
Expand Down Expand Up @@ -100,6 +104,9 @@ public function install()
or ! Configuration::updateValue('SG_LATINURLS_CHARS_INDEX', 0)
or ! Configuration::updateValue('SG_LATINURLS_AUTOCONVERT', 1)
or ! Configuration::updateValue('SG_LATINURLS_CONVERTCURSOR', 'null')
or ! Configuration::updateValue('SG_LATINURLS_DEFEXECTIME', 25)
or ! Configuration::updateValue('SG_LATINURLS_USEEXECTIME', 0)
or ! Configuration::updateValue('SG_LATINURLS_BATCHSIZE', 50)
) {
return false;
}
Expand All @@ -118,6 +125,9 @@ public function uninstall()
or ! Configuration::deleteByName('SG_LATINURLS_CHARS_INDEX')
or ! Configuration::deleteByName('SG_LATINURLS_AUTOCONVERT')
or ! Configuration::deleteByName('SG_LATINURLS_CONVERTCURSOR')
or ! Configuration::deleteByName('SG_LATINURLS_DEFEXECTIME')
or ! Configuration::deleteByName('SG_LATINURLS_USEEXECTIME')
or ! Configuration::deleteByName('SG_LATINURLS_BATCHSIZE')
or ! parent::uninstall()) {
return false;
}
Expand Down Expand Up @@ -215,9 +225,9 @@ public function getContent()
}
$this->_html .= $this->renderMessages();
$this->_html .= $this->renderHelpForm(false, $this->_checkupdate, $this->_hide_helpForm);
$this->_html .= $this->renderTestForm($responce);
$this->_html .= $this->renderConfigForm($this->_hide_configForm, $this->_confForm_getfrompost);
$this->_html .= $this->renderActionForm();
$this->_html .= $this->renderConfigForm($this->_hide_configForm, $this->_confForm_getfrompost);
$this->_html .= $this->renderTestForm($responce);
$this->_html .= $this->renderProductList();
return $this->_html;
}
Expand Down Expand Up @@ -250,6 +260,8 @@ public function updateAllProducts()
{
$ret = true;
self::$ignoreHook = true;
$this->def_exec_time = Configuration::get('SG_LATINURLS_DEFEXECTIME');
$this->use_exec_time = Configuration::get('SG_LATINURLS_USEEXECTIME');
$pr_array = $this->getAllProducts();

$max_executiontime = @ini_get('max_execution_time');
Expand All @@ -260,26 +272,31 @@ public function updateAllProducts()
if ($conf_cur == 'null') {
$cursor = 1;
} else {
$cursor = (int) $conf_cur + 1;
$cursor = (int) $conf_cur;
}
$start_time = microtime(true);

if (function_exists('memory_get_peak_usage'))
do {
$cursor = (int) $this->updateAllProductsLoop($cursor, $pr_array);
$time_elapsed = microtime(true) - $start_time;
} while ($cursor < count($pr_array) && Tools::getMemoryLimit() > memory_get_peak_usage() && $time_elapsed < $max_executiontime);
else
if ($this->use_exec_time) {
$start_time = microtime(true);

if (function_exists('memory_get_peak_usage'))
do {
$cursor = (int) $this->updateAllProductsLoop($cursor, $pr_array);
$time_elapsed = microtime(true) - $start_time;
} while ($cursor <= count($pr_array) && Tools::getMemoryLimit() > memory_get_peak_usage() && $time_elapsed < $max_executiontime);
else
do {
$cursor = (int) $this->updateAllProductsLoop($cursor, $pr_array);
$time_elapsed = microtime(true) - $start_time;
} while ($cursor <= count($pr_array) && $time_elapsed < $max_executiontime);
} else {
do {
$cursor = (int) $this->updateAllProductsLoop($cursor, $pr_array);
$time_elapsed = microtime(true) - $start_time;
} while ($cursor < count($pr_array) && $time_elapsed < $max_executiontime);

if ($cursor >= count($pr_array)) {
} while ($cursor <= count($pr_array));
}
if ($cursor > count($pr_array)) {
Configuration::updateValue('SG_LATINURLS_CONVERTCURSOR', 'null');
$ret = true;
} else {
Configuration::updateValue('SG_LATINURLS_CONVERTCURSOR', $cursor);
$this->_warnings[] = $this->l('Proccess paused due to memory or time constrains. Please try again to continue.');
$ret = false;
}
Expand All @@ -291,19 +308,24 @@ public function updateAllProducts()

private function updateAllProductsLoop($cursor, $pr_array)
{
$limit = 10;
$limit = (int) Configuration::get('SG_LATINURLS_BATCHSIZE');
$ret = 0;
for ($i = $cursor; ($i <= count($pr_array) && $i < $cursor + $limit); $i++) {
$p = new ProductCore($pr_array[$i]);
$p = new Product($pr_array[$i]);
foreach ($p->name as $key => $value) {
$p->link_rewrite[$key] = $this->parseProductName($value);
}
$ret1 = $p->save();
Configuration::updateValue('SG_LATINURLS_CONVERTCURSOR', $i + 1);
if (!$ret1) {
$this->_errors[] = sprintf($this->l('Failed to update product with id %d.'), $pr_array[$i]);
}
$ret = $i;
$ret = $i + 1;
}
// //time waste
// for ($l = 1; $l < 10000000; $l++) {
// $a = sin($l * 0.54556652);
// }
return $ret;
}

Expand Down Expand Up @@ -754,6 +776,49 @@ public function renderConfigForm($hide = false, $getFromPost = false)
),
'hint' => $this->l('Toggle whether fix friendly urls on product save.'),
),
array(
'type' => 'html',
'html_content' => '<hr class="sakgiok_latinurls_form_hr">',
'col' => '12',
'label' => '',
'name' => 'sep',
),
array(
'type' => 'html',
'html_content' => '<h3 id="sakgiok_latinurls_advheader">' . $this->l('Advanced Options') . '</h3>',
'col' => '12',
'label' => '',
'name' => 'sep',
),
array(
'type' => 'switch',
'label' => $this->l('Use php\'s max_execution_time when building all products\' friendly urls.'),
'name' => 'SG_LATINURLS_USEEXECTIME',
'is_bool' => true,
'values' => array(
array(
'value' => 1,
),
array(
'value' => 0,
),
),
'hint' => $this->l('Toggle whether to use php\'s max_execution_time value to pause the process or let it run.'),
),
array(
'type' => 'text',
'label' => $this->l('max_execution_time default value (seconds)'),
'name' => 'SG_LATINURLS_DEFEXECTIME',
'hint' => $this->l('If max_execution_time is greater than this value, or is 0, this value will be used.'),
'class' => 'fixed-width-xxl',
),
array(
'type' => 'text',
'label' => $this->l('Product processing batch size.'),
'name' => 'SG_LATINURLS_BATCHSIZE',
'hint' => $this->l('Determines how many products will be processed before checking for a timeout.'),
'class' => 'fixed-width-xxl',
),
),
'submit' => array(
'title' => $this->l('Save'),
Expand Down Expand Up @@ -805,10 +870,16 @@ protected function getConfigFieldsValues($getfrompost = false)
$ret['SG_LATINURLS_AUTOCONVERT'] = Tools::getValue('SG_LATINURLS_AUTOCONVERT', 1);
$ret['SG_LATINURLS_CHARS_INDEX'] = Tools::getValue('SG_LATINURLS_CHARS_INDEX', 0);
$ret['SG_LATINURLS_AUTO_UPDATE'] = Tools::getValue('SG_LATINURLS_AUTO_UPDATE', 0);
$ret['SG_LATINURLS_USEEXECTIME'] = Tools::getValue('SG_LATINURLS_USEEXECTIME', 1);
$ret['SG_LATINURLS_DEFEXECTIME'] = Tools::getValue('SG_LATINURLS_DEFEXECTIME', 29);
$ret['SG_LATINURLS_BATCHSIZE'] = Tools::getValue('SG_LATINURLS_BATCHSIZE', 50);
} else {
$ret['SG_LATINURLS_AUTOCONVERT'] = Configuration::get('SG_LATINURLS_AUTOCONVERT');
$ret['SG_LATINURLS_CHARS_INDEX'] = Configuration::get('SG_LATINURLS_CHARS_INDEX');
$ret['SG_LATINURLS_AUTO_UPDATE'] = Configuration::get('SG_LATINURLS_AUTO_UPDATE');
$ret['SG_LATINURLS_USEEXECTIME'] = Configuration::get('SG_LATINURLS_USEEXECTIME');
$ret['SG_LATINURLS_DEFEXECTIME'] = Configuration::get('SG_LATINURLS_DEFEXECTIME');
$ret['SG_LATINURLS_BATCHSIZE'] = Configuration::get('SG_LATINURLS_BATCHSIZE');
}

return $ret;
Expand All @@ -827,6 +898,9 @@ private function _postproccess_conf()
$ret &= Configuration::updateValue('SG_LATINURLS_AUTO_UPDATE', Tools::getValue('SG_LATINURLS_AUTO_UPDATE', 0));
$ret &= Configuration::updateValue('SG_LATINURLS_AUTOCONVERT', Tools::getValue('SG_LATINURLS_AUTOCONVERT', 1));
$ret &= Configuration::updateValue('SG_LATINURLS_CHARS_INDEX', Tools::getValue('SG_LATINURLS_CHARS_INDEX', 0));
$ret &= Configuration::updateValue('SG_LATINURLS_USEEXECTIME', Tools::getValue('SG_LATINURLS_USEEXECTIME', 0));
$ret &= Configuration::updateValue('SG_LATINURLS_DEFEXECTIME', Tools::getValue('SG_LATINURLS_DEFEXECTIME', 25));
$ret &= Configuration::updateValue('SG_LATINURLS_BATCHSIZE', Tools::getValue('SG_LATINURLS_BATCHSIZE', 50));
if ($ret) {
$this->_msg[] = $this->l('Successful update.');
} else {
Expand Down
7 changes: 7 additions & 0 deletions sakgiok_latinurls/translations/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_10e5f73818e694fef13d7adf5d77aae1'] = 'Το αρχείο που θα χρησιμοποιηθεί κατά την μετατροπή χαρακτήρων.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_5987cb46dfe43d90577f4d4f0554ae12'] = 'Αυτόματη παραγωγή url κατά την αποθήκευση προϊόντος';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_a6c5d1c765c99ca7fd4a736ff531903d'] = 'Όταν αποθηκεύεται ένα προϊόν, αν η επιλογή είναι επιλεγμένη, θα δημιουργείται και θα αποθηκεύεται και το φιλικό url.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_9dfc5d5738312210c3c75e68a468691d'] = 'Προχωρημένες Επιλογές';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_651f22aa6ba0126ab6e603e26e8b7bfa'] = 'Χρήση του max_execution_time της php κατά τη δημιουργία friendly url όλων των προϊόντων.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_982c75a89caad48c08d3af53dcfd6d15'] = 'Επιλέξτε αν θα χρησιμοποιείται η τιμή max_execution_time της php για να σταματήσετε τη διαδικασία ή αν θα την αφήσετε να τρέξει.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_14a9e3b6e942f3d26225f72ac867ac03'] = 'Η εξ\' ορισμού τιμή max_execution_time (σε δευτερόλεπτα).';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_438e05464e1840e2d0ab6091a1d7e3c1'] = 'Αν η τιμή max_execution_time είναι μεγαλύτερη από αυτή τη τιμή, ή αν είναι μηδέν, θα χρησιμοποιείται αυτή η τιμή.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_f434a56382a96a097dc50e3e523f14f5'] = 'Μέγεθος της δεσμίδας κατά την επεξεργασίας προϊόντων.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_083ec7114e88c5434dcdf18be998fd87'] = 'Καθορίζει πόσα προϊόντα θα επεξεργαστούν πριν ελεγχθεί αν θα υπάρξει timeout.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_c9cc8cce247e49bae79f15173ce97354'] = 'Αποθήκευση';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_254f642527b45bc260048e30704edb39'] = 'Διαμόρφωση';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_b4a34d3f58b039e7685c2e39b5413757'] = 'Επιτυχής ενημέρωση.';
Expand Down
7 changes: 7 additions & 0 deletions sakgiok_latinurls/translations/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_10e5f73818e694fef13d7adf5d77aae1'] = 'The file to use for transforming from one language to another.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_5987cb46dfe43d90577f4d4f0554ae12'] = 'Auto fix friendly url on product save';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_a6c5d1c765c99ca7fd4a736ff531903d'] = 'Toggle whether fix friendly urls on product save.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_9dfc5d5738312210c3c75e68a468691d'] = 'Advanced Options';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_651f22aa6ba0126ab6e603e26e8b7bfa'] = 'Use php\'s max_execution_time when building all products\' friendly urls.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_982c75a89caad48c08d3af53dcfd6d15'] = 'Toggle whether to use php\'s max_execution_time value to pause the process or let it run.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_14a9e3b6e942f3d26225f72ac867ac03'] = 'max_execution_time default value (seconds)';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_438e05464e1840e2d0ab6091a1d7e3c1'] = 'If max_execution_time is greater than this value, or is 0, this value will be used.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_f434a56382a96a097dc50e3e523f14f5'] = 'Product processing batch size.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_083ec7114e88c5434dcdf18be998fd87'] = 'Determines how many products will be processed before checking for a timeout.';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_c9cc8cce247e49bae79f15173ce97354'] = 'Save';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_254f642527b45bc260048e30704edb39'] = 'Configuration';
$_MODULE['<{sakgiok_latinurls}prestashop>sakgiok_latinurls_b4a34d3f58b039e7685c2e39b5413757'] = 'Successful update.';
Expand Down
3 changes: 3 additions & 0 deletions sakgiok_latinurls/views/css/sakgiok_latinulrs_admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,7 @@
width: 25px;
height: auto;
margin: 0 0 0 10px;
}
#sakgiok_latinurls_advheader{

}

0 comments on commit fff30ce

Please # to comment.