[Est:5] [Prestashop] - Master file refactor
Closed this issue · 8 comments
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:
Doing a previous research of all the functions and methods.
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()
✅ 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.
HookManager has to be shorten since some functions which contains protected attributes cannot be migrated.
Small update: createStore won't be moved from DoofinderInstallation class since it fits very well here.
I'm going to add some translations 🤞
The translations were messed up after the refactor, but luckily I've noticed it before releasing the major changes in the translations
It's live now 🙌