Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLUGINRANGERS-234 | Master file refactor step 8: Moved lib entities to src/Entity + minor adjustments #249

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d91b736
feat: Separated install process + autoloader. First approach
davidmolinacano Sep 30, 2024
990f23c
fix: Fixed several files
davidmolinacano Oct 1, 2024
a62c97a
feat: use Db; in upgrade 4.5.0
davidmolinacano Oct 1, 2024
2916b0f
fix: Fixes after testing everything carefully
davidmolinacano Oct 1, 2024
1a71b0d
feat: Resolved conflicts
davidmolinacano Oct 1, 2024
fd6a171
feat: Renamed buildFeedUrl to getFeedUrl
davidmolinacano Oct 1, 2024
c4bb0a4
feat: Changes to pass the Prestashop validator at 100%
davidmolinacano Oct 1, 2024
1505b69
feat: Migrated HookManager and UpdateOnSave
davidmolinacano Oct 3, 2024
86cd33d
feat: Refactor of DoofinderApi + creation of DoofinderAdminPanelView …
davidmolinacano Oct 4, 2024
5146d53
feat: Convert variables to camelCase + namespaces in Api classes
davidmolinacano Oct 7, 2024
1a65a36
feat: Several improvements + fix save advanced settings
davidmolinacano Oct 7, 2024
ffedf3a
feat: More camelCase changes
davidmolinacano Oct 7, 2024
4681a05
feat: Renamed all the references to dfTools.class.php + fixed some va…
davidmolinacano Oct 7, 2024
449875f
feat: More camelCase adjustments
davidmolinacano Oct 7, 2024
3850382
feat: phpcs fixer
davidmolinacano Oct 7, 2024
1dfb60e
fix: Removed usage of a function to keep the feed as it was before
davidmolinacano Oct 7, 2024
7cee005
feat: More camelCase changes
davidmolinacano Oct 7, 2024
faa5a0c
feat: Renamed build classes + added namespaces
davidmolinacano Oct 7, 2024
904661f
feat: Added LanguageManager + landing minor refactors
davidmolinacano Oct 8, 2024
ee7a86b
feat: Moved up public functions in main file
davidmolinacano Oct 8, 2024
40fc988
feat: Complete refactor
davidmolinacano Oct 8, 2024
5812b9f
feat: Simplified and improved autoloader
davidmolinacano Oct 8, 2024
d012d0e
feat: Moved entities to src/Entity directory + minor improvements
davidmolinacano Oct 9, 2024
72c4945
feat: Removed useless new Shop() instantiation
davidmolinacano Oct 9, 2024
710c870
feat: Resolved conflicts
davidmolinacano Oct 14, 2024
87fcf37
feat: Classname change + minor fixes
davidmolinacano Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

class Autoloader
{
// Exceptions based on: https://devdocs.prestashop-project.org/8/modules/creation/module-file-structure/
const EXCEPTIONS_FOR_UNCAPITALIZE = ['Entity', 'Controller'];

/**
* Registers the autoloader according to PrestaShop standards, which are PSR-12 standards.
* More info at: https://www.php-fig.org/psr/psr-12/
Expand Down Expand Up @@ -74,6 +77,10 @@ private static function pathFromNamespace($fullNameSpace)
*/
private static function uncapitalize($text)
{
if (in_array($text, self::EXCEPTIONS_FOR_UNCAPITALIZE, true)) {
return $text;
}

return strtolower(substr($text, 0, 1)) . substr($text, 1);
}
}
Expand Down
6 changes: 3 additions & 3 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DfTools;
use PrestaShop\Module\Doofinder\Lib\DoofinderConfig;
use PrestaShop\Module\Doofinder\Lib\DoofinderConstants;
use PrestaShop\Module\Doofinder\Src\Entity\DfTools;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConfig;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConstants;

$root_path = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
$config_file_path = $root_path . '/config/config.inc.php';
Expand Down
4 changes: 2 additions & 2 deletions controllers/front/landing.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DoofinderApiLanding;
use PrestaShop\Module\Doofinder\Lib\SearchEngine;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderApiLanding;
use PrestaShop\Module\Doofinder\Src\Entity\SearchEngine;
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
use PrestaShop\PrestaShop\Adapter\Product\ProductColorsRetriever;
Expand Down
4 changes: 2 additions & 2 deletions doofinder-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DoofinderApi;
use PrestaShop\Module\Doofinder\Lib\DoofinderInstallation;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderApi;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderInstallation;

$rootPath = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
$configFilePath = $rootPath . '/config/config.inc.php';
Expand Down
12 changes: 6 additions & 6 deletions doofinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

require_once 'autoloader.php';

use PrestaShop\Module\Doofinder\Lib\DoofinderAdminPanelView;
use PrestaShop\Module\Doofinder\Lib\DoofinderInstallation;
use PrestaShop\Module\Doofinder\Lib\DoofinderScript;
use PrestaShop\Module\Doofinder\Lib\HookManager;
use PrestaShop\Module\Doofinder\Lib\SearchEngine;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderAdminPanelView;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderInstallation;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderScript;
use PrestaShop\Module\Doofinder\Src\Entity\HookManager;
use PrestaShop\Module\Doofinder\Src\Entity\SearchEngine;

class Doofinder extends Module
{
Expand Down Expand Up @@ -69,7 +69,7 @@ public function install()
/**
* Uninstall the module and its dependencies
*
* @return void
* @return bool
*/
public function uninstall()
{
Expand Down
4 changes: 2 additions & 2 deletions feeds/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DfCategoryBuild;
use PrestaShop\Module\Doofinder\Lib\DfTools;
use PrestaShop\Module\Doofinder\Src\Entity\DfCategoryBuild;
use PrestaShop\Module\Doofinder\Src\Entity\DfTools;

if (function_exists('set_time_limit')) {
@set_time_limit(3600 * 2);
Expand Down
4 changes: 2 additions & 2 deletions feeds/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DfCmsBuild;
use PrestaShop\Module\Doofinder\Lib\DfTools;
use PrestaShop\Module\Doofinder\Src\Entity\DfCmsBuild;
use PrestaShop\Module\Doofinder\Src\Entity\DfTools;

if (function_exists('set_time_limit')) {
@set_time_limit(3600 * 2);
Expand Down
4 changes: 2 additions & 2 deletions feeds/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DfTools;
use PrestaShop\Module\Doofinder\Lib\DoofinderConstants;
use PrestaShop\Module\Doofinder\Src\Entity\DfTools;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConstants;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
6 changes: 3 additions & 3 deletions landing.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DoofinderConfig;
use PrestaShop\Module\Doofinder\Lib\DoofinderConstants;
use PrestaShop\Module\Doofinder\Lib\LanguageManager;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConfig;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConstants;
use PrestaShop\Module\Doofinder\Src\Entity\LanguageManager;

$rootPath = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
$configFilePath = $rootPath . '/config/config.inc.php';
Expand Down
4 changes: 2 additions & 2 deletions lib/DfCategoryBuild.php → src/Entity/DfCategoryBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -71,7 +71,7 @@ private function buildCategory($idCategory)
$c['meta_description'] = DfTools::cleanString($category->meta_description);
$c['tags'] = DfTools::cleanString($category->meta_keywords);
$c['link'] = $this->link->getCategoryLink($category);
$c['image_link'] = $category->id_image ? $this->link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default') : '';
$c['image_link'] = $category->id_image ? $this->link->getCatImageLink($category->link_rewrite, $category->id_image, \ImageType::getFormattedName('category')) : '';

return $c;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/DfCmsBuild.php → src/Entity/DfCmsBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
2 changes: 1 addition & 1 deletion lib/DfProductBuild.php → src/Entity/DfProductBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
39 changes: 19 additions & 20 deletions lib/DfTools.php → src/Entity/DfTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -61,10 +61,10 @@ public static function prepareSQL($sql, $args = [])
public static function limitSQL($sql, $limit = false, $offset = false)
{
if (false !== $limit && is_numeric($limit)) {
$sql .= ' LIMIT ' . intval($limit);
$sql .= ' LIMIT ' . (int) $limit;

if (false !== $offset && is_numeric($offset)) {
$sql .= ' OFFSET ' . intval($offset);
$sql .= ' OFFSET ' . (int) $offset;
}
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public static function getAvailableImageSizes()
`products` = 1
ORDER BY
CASE
WHEN name = 'home_default' THEN '1'
WHEN name = '" . \ImageType::getFormattedName('home') . "' THEN '1'
END DESC;
";

Expand Down Expand Up @@ -145,9 +145,9 @@ public static function versionGte($minVersion)
$minVersion = explode('.', $minVersion);

foreach ($version as $index => $value) {
if (intval($value) > intval($minVersion[$index])) {
if ((int) $value > (int) $minVersion[$index]) {
return true;
} elseif (intval($value) < intval($minVersion[$index])) {
} elseif ((int) $value < (int) $minVersion[$index]) {
return false;
}
}
Expand Down Expand Up @@ -868,13 +868,13 @@ public static function getCategoriesForProductIdAndLanguage($idProduct, $idLang,

foreach (\Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql) as $i => $row) {
if (!$i) {
$idCategory0 = intval($row['id_category']);
$nleft0 = intval($row['nleft']);
$nright0 = intval($row['nright']);
$idCategory0 = (int) $row['id_category'];
$nleft0 = (int) $row['nleft'];
$nright0 = (int) $row['nright'];
} else {
$idCategory1 = intval($row['id_category']);
$nleft1 = intval($row['nleft']);
$nright1 = intval($row['nright']);
$idCategory1 = (int) $row['id_category'];
$nleft1 = (int) $row['nleft'];
$nright1 = (int) $row['nright'];

if ($nleft1 < $nleft0 && $nright1 > $nright0) {
// $idCategory1 is an ancestor of $idCategory0
Expand Down Expand Up @@ -981,7 +981,7 @@ public static function getCmsPages($idLang, $idShop, $active = true)

public static function truncateText($text, $length)
{
$l = intval($length);
$l = (int) $length;
$c = trim(preg_replace('/\s+/', ' ', $text));

if (strlen($c) <= $l) {
Expand Down Expand Up @@ -1169,7 +1169,7 @@ public static function getCurrencyForLanguageFromRequest(\Language $lang)
{
if ($idCurrency = \Tools::getValue('currency')) {
if (is_numeric($idCurrency)) {
$idCurrency = intval($idCurrency);
$idCurrency = (int) $idCurrency;
} else {
$idCurrency = \Currency::getIdByIsoCode(strtoupper($idCurrency));
}
Expand Down Expand Up @@ -1197,8 +1197,7 @@ public static function getCurrencyForLanguageFromRequest(\Language $lang)
public static function getModuleLink($path, $ssl = false)
{
$context = \Context::getContext();
$shop = new \Shop($context->shop->id);
$base = (($ssl && \Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://') . $shop->domain;
$base = (($ssl && \Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://') . $context->shop->domain;

return $base . _MODULE_DIR_ . basename(dirname(__FILE__)) . '/' . $path;
}
Expand Down Expand Up @@ -1411,17 +1410,17 @@ public static function getOnsalePrice($productId, $includeTaxes, $variantId = nu

private static function getVariantUrl($product, $context)
{
global $lang, $shop;
$cfgModRewrite = self::cfg($shop->id, 'PS_REWRITING_SETTINGS', DoofinderConstants::YES);
$context = \Context::getContext();
$cfgModRewrite = self::cfg($context->shop->id, 'PS_REWRITING_SETTINGS', DoofinderConstants::YES);

return self::cleanURL(
$context->link->getProductLink(
(int) $product['id_product'],
$product['link_rewrite'],
$product['cat_link_rew'],
$product['ean13'],
$lang->id,
$shop->id,
$context->language->id,
$context->shop->id,
(int) $product['id_product_attribute'],
$cfgModRewrite,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
13 changes: 4 additions & 9 deletions lib/DoofinderApi.php → src/Entity/DoofinderApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Gilles Devaux (<[email protected]>) (https://github.com/flaptor/indextank-php)
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -372,15 +372,10 @@ public function removeTerm($filterName, $term)
if ($this->optionExists('filter') && isset($this->searchOptions['filter'][$filterName])
&& in_array($term, $this->searchOptions['filter'][$filterName])
) {
function filter_me($value)
{
global $term;

return $value != $term;
}

$this->searchOptions['filter'][$filterName] =
array_filter($this->searchOptions['filter'][$filterName], 'filter_me');
array_filter($this->searchOptions['filter'][$filterName], function ($value) use ($term) {
return $value !== $term;
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
}

class DoofinderApiUniqueScript
class DoofinderApiSingleScript
{
private $installationId;
private $apiKey;
Expand All @@ -33,13 +33,13 @@ public function __construct($installationId, $region, $apiKey)
}

/**
* Make a request to the API to SET unique script flag to notify the migration of this customer
* Make a request to the API to SET single script flag to notify the migration of this customer
*
* This function does not require any parameters.
*
* @return mixed The response from the API request
*/
public function set_unique_script_flag()
public function setSingleScriptFlag()
{
$endpoint = '/prestashop/migrate-unique-script';

Expand Down
2 changes: 1 addition & 1 deletion lib/DoofinderConfig.php → src/Entity/DoofinderConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Loading
Loading