doofinder / doofinder-prestashop

🔍🛍 Prestashop search module to improve accuracy and fast response with Doofinder
13 stars 6 forks source link

[Est:5] [Prestashop] - Master file refactor #234

Closed eduardogomez97 closed 1 month ago

eduardogomez97 commented 3 months ago

We have been reviewing the doofinder.php file and believe that it should be refactored as it is a monolith with too much functionality. From update on save stuff that can be taken out to its own files and response checks for the different apis we have. Investigate what else could be moved and make the code cleaner.

Some examples:

Image Image

davidmolinacano commented 2 months ago

Doing a previous research of all the functions and methods.

davidmolinacano commented 2 months ago

After reviewing every function I came to the following proposal:

Must be kept

function __construct()

function install()

function uninstall()

function hookModuleRoutes()

lib/doofinder_installation.php

function installDb()

function autoinstaller($shop_id = null)

function installTabs()

function uninstallTabs()

function uninstallDb()

function deleteConfigVars()

lib/includes/url_manager.php

function getInstallUrl($region)

function getShopBaseURI($shop)

function getShopURL($shop_id)

function buildFeedUrl($shop_id, $language, $currency) → rename to getFeedUrl($shop_id, $language, $currency)

function getProcessCallbackUrl()

lib/includes/hook_manager.php

function hookModuleRoutes()

function configureHookCommon($params = false)

function hookHeader($params)

lib/includes/hooks/update_on_save.php

function proccessHookUpdateOnSave($object, $id_object, $action)

lib/includes/hooks/update_on_save/product.php

function hookActionProductSave($params)

function hookActionProductDelete($params)

lib/includes/hooks/update_on_save/cms.php

function hookActionObjectCmsAddAfter($params)

function hookActionObjectCmsUpdateAfter($params)

function hookActionObjectCmsDeleteAfter($params)

lib/includes/hooks/update_on_save/category.php

function hookActionObjectCategoryAddAfter($params)

function hookActionObjectCategoryUpdateAfter($params)

function hookActionObjectCategoryDeleteAfter($params)

lib/includes/update_on_save.php

function allowProcessItemsQueue()

function setExecUpdateOnSave()

function addItemQueue($object, $id_object, $id_shop, $action)

function processItemQueue($id_shop)

function getItemsQueue($id_shop, $type, $action = 'update')

function deleteItemsQueue($id_shop)

function sendProductApi($products, $id_shop, $id_lang, $id_currency, $action = 'update')

function sendCmsApi($cms_pages, $id_shop, $id_lang, $id_currency, $action = 'update')

function sendCategoryApi($categories, $id_shop, $id_lang, $id_currency, $action = 'update')

function updateItemsApi($hashid, $type, $payload)

function deleteItemsApi($hashid, $type, $payload)

function deleteItemsApi($hashid, $type, $payload)

function indexApiInvokeReindexing()

function is_valid_update_on_save() → Change to camelCase

lib/doofinder_api.php (already exists)

function testDoofinderApi($onlyOneLang = false)

function searchOnApi($string, $page = 1, $page_size = 12, $timeout = 8000, $filters = null, $return_facets = false)

function saveApiData($apikey, $api_endpoint, $admin_endpoint)

function checkApiKey($text = false)

lib/includes/language_manager.php

function getLanguageByHashid($hashid)

function getLanguageIdByLocale($locale)

function getIsoCodeById($id)

function getLanguageCode($code)

lib/includes/search_engine.php

function SetSearchEnginesByConfig()

function getHashId($id_lang, $id_currency)

lib/includes/store.php

function createStore($shop)

lib/includes/doofinder_admin_panel_view.php

function getContent()

function isConfigured()

function showNewShopForm($shop)

function renderFormDataFeed($adv = false)

function renderFormAdvanced()

function renderFeedURLs()

function getWarningMultishopHtml()

All display functions

lib/includes/doofinder_script_view.php

function displayScriptLiveLayer()

function displayScriptV7() → It will be deleted

function searchLayerMustBeInitialized()

lib/includes/doofinder_config.php

function getConfigFormSearchLayer()

function getConfigFormDataFeed($valid_update_on_save = false)

function getConfigFormValuesDataFeed()

function getConfigFormAdvanced()

function getConfigFormValuesAdvanced()

function getBooleanFormValue()

function checkOutsideConnection()

function setDefaultShopConfig($shopGroupId, $shopId)

function debug($message)

lib/includes/form_processor.php

function postProcess()

davidmolinacano commented 2 months ago

✅ Validated with @sofia-doofinder

She thinks that the proposed structure is cleaner and easier to read and understand. After talking to her, we agreed to change the name of the files to PascalCase to fullfil Prestashop coding standards.

davidmolinacano commented 2 months ago

HookManager has to be shorten since some functions which contains protected attributes cannot be migrated.

davidmolinacano commented 1 month ago

Small update: createStore won't be moved from DoofinderInstallation class since it fits very well here.

davidmolinacano commented 1 month ago

I'm going to add some translations 🤞

davidmolinacano commented 1 month ago

The translations were messed up after the refactor, but luckily I've noticed it before releasing the major changes in the translations

davidmolinacano commented 1 month ago

It's live now 🙌