diff --git a/classes/Language.php b/classes/Language.php
index 6e04afa1d..e26d8d760 100644
--- a/classes/Language.php
+++ b/classes/Language.php
@@ -185,16 +185,7 @@ class LanguageCore extends ObjectModel
$resUpdateSQL = $this->loadUpdateSQL();
$resUpdateSQL = true;
- // If url_rewrite is not enabled, we don't need to regenerate .htaccess
- if(!Configuration::get('PS_REWRITING_SETTINGS'))
- return $resUpdateSQL;
-
- return ($resUpdateSQL AND Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
- (int)(Configuration::get('PS_REWRITING_SETTINGS')),
- (int)(Configuration::get('PS_HTACCESS_CACHE_CONTROL')),
- '',
- (int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
- ));
+ return $resUpdateSQL && Tools::generateHtaccess();
}
public function toggleStatus()
@@ -202,15 +193,7 @@ class LanguageCore extends ObjectModel
if (!parent::toggleStatus())
return false;
- // If url_rewrite is not enabled, we don't need to regenerate .htaccess
- if(!Configuration::get('PS_REWRITING_SETTINGS'))
- return true;
- return (Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
- (int)(Configuration::get('PS_REWRITING_SETTINGS')),
- (int)(Configuration::get('PS_HTACCESS_CACHE_CONTROL')),
- '',
- (int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
- ));
+ return Tools::generateHtaccess();
}
public function checkFiles()
@@ -470,16 +453,7 @@ class LanguageCore extends ObjectModel
unlink(dirname(__FILE__).'/../img/l/'.$this->id.'.jpg');
}
- // If url_rewrite is not enabled, we don't need to regenerate .htaccess
- if(!Configuration::get('PS_REWRITING_SETTINGS'))
- return true;
-
- return Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
- (int)(Configuration::get('PS_REWRITING_SETTINGS')),
- (int)(Configuration::get('PS_HTACCESS_CACHE_CONTROL')),
- '',
- (int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
- );
+ return Tools::generateHtaccess();
}
@@ -495,17 +469,7 @@ class LanguageCore extends ObjectModel
$result = $result AND $this->delete();
}
- // If url_rewrite is not enabled, we don't need to regenerate .htaccess
- if(!Configuration::get('PS_REWRITING_SETTINGS'))
- return true;
-
- Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
- (int)Configuration::get('PS_REWRITING_SETTINGS'),
- (int)Configuration::get('PS_HTACCESS_CACHE_CONTROL'),
- '',
- (int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
- );
-
+ Tools::generateHtaccess();
return $result;
}
@@ -630,21 +594,10 @@ class LanguageCore extends ObjectModel
public function update($nullValues = false)
{
-
-
if (!parent::update($nullValues))
return false;
- // If url_rewrite is not enabled, we don't need to regenerate .htaccess
- if(!Configuration::get('PS_REWRITING_SETTINGS'))
- return true;
-
- return Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
- (int)(Configuration::get('PS_REWRITING_SETTINGS')),
- (int)(Configuration::get('PS_HTACCESS_CACHE_CONTROL')),
- '',
- (int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
- );
+ return Tools::generateHtaccess();
}
public static function checkAndAddLanguage($iso_code)
diff --git a/classes/Meta.php b/classes/Meta.php
index 2263f4e41..cc7f73ee3 100644
--- a/classes/Meta.php
+++ b/classes/Meta.php
@@ -124,12 +124,7 @@ class MetaCore extends ObjectModel
if (!parent::update($nullValues))
return false;
- return Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
- (int)Configuration::get('PS_REWRITING_SETTINGS'),
- (int)Configuration::get('PS_HTACCESS_CACHE_CONTROL'),
- '',
- (int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
- );
+ return Tools::generateHtaccess();
}
public function delete()
@@ -137,12 +132,7 @@ class MetaCore extends ObjectModel
if (!parent::delete())
return false;
- return Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
- (int)Configuration::get('PS_REWRITING_SETTINGS'),
- (int)Configuration::get('PS_HTACCESS_CACHE_CONTROL'),
- '',
- (int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
- );
+ return Tools::generateHtaccess();
}
public function deleteSelection($selection)
@@ -156,12 +146,7 @@ class MetaCore extends ObjectModel
$result = $result AND $this->delete();
}
- return Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
- (int)Configuration::get('PS_REWRITING_SETTINGS'),
- (int)Configuration::get('PS_HTACCESS_CACHE_CONTROL'),
- '',
- (int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
- );
+ return Tools::generateHtaccess();
}
public static function getEquivalentUrlRewrite($new_id_lang, $id_lang, $url_rewrite)
diff --git a/classes/Tools.php b/classes/Tools.php
index 83b6c0c15..9cfe821c8 100644
--- a/classes/Tools.php
+++ b/classes/Tools.php
@@ -1493,10 +1493,23 @@ class ToolsCore
return self::getHttpHost();
}
- public static function generateHtaccess($path, $rewrite_settings, $cache_control, $specific = '', $disable_multiviews = false)
+ public static function generateHtaccess($path = null, $rewrite_settings = null, $cache_control = null, $specific = '', $disable_multiviews = null)
{
if (defined('PS_INSTALLATION_IN_PROGRESS'))
- return;
+ return true;
+
+ if (!Configuration::get('PS_REWRITING_SETTINGS'))
+ return true;
+
+ // Default values for parameters
+ if (is_null($path))
+ $path = _PS_ROOT_DIR_.'/.htaccess';
+ if (is_null($rewrite_settings))
+ $rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
+ if (is_null($cache_control))
+ $cache_control = (int)Configuration::get('PS_HTACCESS_CACHE_CONTROL');
+ if (is_null($disable_multiviews))
+ $disable_multiviews = (int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS');
// Check current content of .htaccess and save all code outside of prestashop comments
$specific_before = $specific_after = '';
diff --git a/controllers/admin/AdminGeneratorController.php b/controllers/admin/AdminGeneratorController.php
index 53a4911c8..a6d39440f 100644
--- a/controllers/admin/AdminGeneratorController.php
+++ b/controllers/admin/AdminGeneratorController.php
@@ -31,9 +31,9 @@ class AdminGeneratorControllerCore extends AdminController
public function __construct()
{
- $this->ht_file = dirname(__FILE__).'/../../.htaccess';
- $this->rb_file = dirname(__FILE__).'/../../robots.txt';
- $this->sm_file = dirname(__FILE__).'/../../sitemap.xml';
+ $this->ht_file = _PS_ROOT_DIR_.'/.htaccess';
+ $this->rb_file = _PS_ROOT_DIR_.'/robots.txt';
+ $this->sm_file = _PS_ROOT_DIR_.'/sitemap.xml';
$this->rb_data = $this->getRobotsContent();
return parent::__construct();
@@ -68,11 +68,7 @@ class AdminGeneratorControllerCore extends AdminController
Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int)Tools::getValue('PS_HTACCESS_CACHE_CONTROL'));
Configuration::updateValue('PS_REWRITING_SETTINGS', (int)Tools::getValue('PS_REWRITING_SETTINGS'));
Configuration::updateValue('PS_HTACCESS_DISABLE_MULTIVIEWS', (int)Tools::getValue('PS_HTACCESS_DISABLE_MULTIVIEWS'));
- if (Tools::generateHtaccess(
- $this->ht_file,
- Configuration::get('PS_REWRITING_SETTINGS'),
- Configuration::get('PS_HTACCESS_CACHE_CONTROL'), '',
- Tools::getValue('PS_HTACCESS_DISABLE_MULTIVIEWS')))
+ if (Tools::generateHtaccess($this->ht_file, null, null, '', Tools::getValue('PS_HTACCESS_DISABLE_MULTIVIEWS')))
Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token);
$this->_errors[] = $this->l('Cannot write into file:').' '.$this->ht_file.'
'.$this->l('Please check write permissions.');
}
diff --git a/controllers/admin/AdminShopUrlController.php b/controllers/admin/AdminShopUrlController.php
index a1f348652..05ceb1492 100644
--- a/controllers/admin/AdminShopUrlController.php
+++ b/controllers/admin/AdminShopUrlController.php
@@ -286,7 +286,7 @@ class AdminShopUrlControllerCore extends AdminController
parent::processAdd($token);
if (!$this->_errors)
- Tools::generateHtaccess(dirname(__FILE__).'/../../.htaccess', Configuration::get('PS_REWRITING_SETTINGS'), Configuration::get('PS_HTACCESS_CACHE_CONTROL'), '');
+ Tools::generateHtaccess();
}
protected function afterUpdate($object)