Suite mise à jour vers 1.6.2.15



  • Salut,

    J'ai simplement fait la mise à jour de version sans le moindre souci, sauf que tout de suite après, j'ai voulu me rendre dans les modules et voici ce que j'ai eu :

    [PrestaShop] Fatal error in module file :/home6/sc2mediacom/public_html/phenixsuite/modules/commentsalert/commentsalert.php:<br />Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /home6/sc2mediacom/public_html/phenixsuite/modules/commentsalert/commentsalert.php:53
    Stack trace:
    #0 [internal function]: CommentsAlert->__construct()
    #1 /home6/sc2mediacom/public_html/phenixsuite/Core/Foundation/IoC/Core_Foundation_IoC_Container.php(131): ReflectionClass->newInstance()
    #2 /home6/sc2mediacom/public_html/phenixsuite/Core/Foundation/IoC/Core_Foundation_IoC_Container.php(164): Core_Foundation_IoC_Container->makeInstanceFromClassName()
    #3 /home6/sc2mediacom/public_html/phenixsuite/Core/Foundation/IoC/Core_Foundation_IoC_Container.php(177): Core_Foundation_IoC_Container->doMake()
    #4 /home6/sc2mediacom/public_html/phenixsuite/Adapter/Adapter_ServiceLocator.php(52): Core_Foundation_IoC_Container->make()
    #5 /home6/sc2mediacom/public_html/phenixsuite/classes/module/Module.php(1331): Adapter_ServiceLocator::get()
    #6 /home6/sc2mediacom/public_html/phenixsuite/classes/module/Module.php(1295): ModuleCore::coreLoadModule()
    #7 /home6/sc2mediacom/public_html/phenixsuite/classes/controller/AdminController.php(4983): ModuleCore::getInstanceByName()
    #8 /home6/sc2mediacom/public_html/phenixsuite/classes/controller/AdminController.php(4879): AdminControllerCore->displayModuleOptions()
    #9 /home6/sc2mediacom/public_html/phenixsuite/controllers/admin/AdminModulesController.php(2059): AdminControllerCore->fillModuleData()
    #10 /home6/sc2mediacom/public_html/phenixsuite/classes/controller/Controller.php(204): AdminModulesControllerCore->initContent()
    #11 /home6/sc2mediacom/public_html/phenixsuite/classes/Dispatcher.php(405): ControllerCore->run()
    #12 /home6/sc2mediacom/public_html/phenixsuite/admin-phenix/index.php(79): DispatcherCore->dispatch()
    #13 {main}
      thrown
    

    Informations sur votre serveur Linux #1 SMP Tue Aug 9 14:38:15 UTC 2022 x86_64

    Version du logiciel serveur Apache

    Version de PHP 8.1.22

    Limite de mémoire 256M

    Temps d'exécution maximal (max_execution_time) 300

    Version de MySQL 10.6.15-MariaDB

    J'ai donc modifié le module commentsalert de la sorte :

            $this->waiting_approval = ProductComment::getByValidate() ? count(ProductComment::getByValidate()) : 0;
            $this->reported = ProductComment::getReportedComments() ? count(ProductComment::getReportedComments()) : 0;
    
    


  • Bonjour,
    Quelle version du module productcomments ?
    La fonction appellée:

        public static function getByValidate($validate = 0, $deleted = false)
        {
            return Db::getInstance()->executeS('
                SELECT pc.`id_product_comment`, pc.`id_product`, 
                    IF(c.id_customer, CONCAT(c.`firstname`, \' \',  c.`lastname`), pc.customer_name) customer_name, 
                    pc.`title`, pc.`content`, pc.`grade`, pc.`date_add`, pl.`name`
                FROM `'._DB_PREFIX_.'product_comment` pc
                LEFT JOIN `'._DB_PREFIX_.'customer` c 
                    ON(c.`id_customer` = pc.`id_customer`)
                LEFT JOIN `'._DB_PREFIX_.'product_lang` pl 
                    ON(pl.`id_product` = pc.`id_product` 
                    AND pl.`id_lang` = '.(int)Context::getContext()->language->id.Shop::addSqlRestrictionOnLang('pl').')
                WHERE pc.`validate` = '.(int)$validate.'
                ORDER BY pc.`date_add` DESC
            ');
        }
    

    Dans tous les cas ça renvoie un tableau (vide ou pas) sauf si le module n'est pas installé et que les tables n'existent pas.

    Je vais donc mettre à jour le module en modifiant le code ainsi:

    <?php
            
            /**
            
             * 2022-2023 PhenixSuite®
            
             *
            
             * NOTICE OF LICENSE
            
             *
            
             * This source file is subject to the Open Software License (OSL 3.0)
            
             * that is bundled with this package in the file LICENSE.txt.
            
             * It is also available through the world-wide-web at this URL:
            
             * http://opensource.org/licenses/osl-3.0.php
            
             * If you did not receive a copy of the license and are unable to
            
             * obtain it through the world-wide-web, please send an email
            
             * to license@phenixsuite.com so we can send you a copy immediately.
            
             *
            
             * DISCLAIMER
            
             *
            
             * Do not edit or add to this file if you wish to upgrade PhenixSuite to newer
            
             * versions in the future. If you wish to customize PhenixSuite for your
            
             * needs please refer to https://phenixsuite.com for more information.
            
             *
            
             *  @author    PhenixSuite <contact@phenixsuite.com>
            
             *  @copyright 2022-2023 PhenixSuite®
            
             *  @license   https://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
            
             */
            
             
            
            if(!defined('_PS_VERSION_')) {
            
                exit;
            
            }
            
            
            
            class CommentsAlert extends Module
            
            {
            
                private $waiting_approval = 0;
            
                private $reported = 0;
            
                private $associated = false;
            
                
            
                public function __construct()
            
                {
            
                    $this->name = 'commentsalert';
            
                    $this->tab = 'administration';
            
                    $this->version = '1.3';
            
                    $this->author = 'Eolia';
            
                    $this->need_instance = 0;
            
                    $this->ps_versions_compliancy = array('min' => '1.6', 'max' => '1.6.99.99');
            
                    $this->dependencies = array('productcomments');
            
            
            
                    parent::__construct();
            
            
            
                    $this->displayName = $this->l('Comments Alert');
            
                    $this->description = $this->l('Backoffice visual and sound alert for unapproved and reported comments.');
            
                    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
            
            
            
                    if(Module::isInstalled('productcomments')) {
            
                        if(file_exists(_PS_ROOT_DIR_.'/modules/productcomments/ProductComment.php')) {
            
                            require_once(_PS_ROOT_DIR_.'/modules/productcomments/ProductComment.php');
            
                        }
            
                        $this->associated = true;
            
                        $this->waiting_approval = count(ProductComment::getByValidate(0, false));
            
                        $this->reported = count(ProductComment::getReportedComments());
            
                    }
            
                }
            
            
            
                public function install()
            
                {
            
                    if(parent::install() == false
            
                        || !$this->registerHook('actionAdminControllerSetMedia')
            
                        || !$this->registerHook('displayBackOfficeTop')
            
                    ) {
            
                        return false;
            
                    }
            
                    Configuration::updateValue('COMMENTS_ALERT_LAST_AWAITING', 0);
            
                    Configuration::updateValue('COMMENTS_ALERT_LAST_REPORT', 0);
            
            
            
                    return true;
            
                }
            
            
            
                public function uninstall()
            
                {
            
                    if(!parent::uninstall() 
            
                        || !$this->unregisterHook('actionAdminControllerSetMedia') 
            
                        || !$this->unregisterHook('displayBackOfficeTop')
            
                    ) {
            
                        return false;
            
                    }
            
                    Configuration::deleteByName('COMMENTS_ALERT_LAST_AWAITING');
            
                    Configuration::deleteByName('COMMENTS_ALERT_LAST_REPORT');
            
            
            
                    return true;
            
                }
            
            
            
                public function hookActionAdminControllerSetMedia()
            
                {
            
                    if(!$this->associated) {
            
                        return;
            
                    }
            
                    $this->context->controller->addJs($this->_path.'views/js/commentsalert.js');
            
                    $this->context->controller->addCss($this->_path.'views/css/commentsalert.css');
            
                }
            
            
            
                public function hookDisplayBackOfficeTop($params)
            
                {
            
                    if(!$this->associated) {
            
                        return;
            
                    }
            
                    if(Tools::getValue('action') == 'updateCommentsInfo' 
            
                        && Tools::getValue('ajax') == 1
            
                    ) {
            
                        $this->ajaxUpdateCommentsInfo();
            
                    }
            
                    else {
            
                        $this->context->smarty->assign(array(
            
                            'link' => $this->context->link,
            
                            'waiting_approval' => min(
            
                                Configuration::get('COMMENTS_ALERT_LAST_AWAITING'), 
            
                                $this->waiting_approval
            
                            ),
            
                            'reported' => min(
            
                                Configuration::get('COMMENTS_ALERT_LAST_LAST_REPORT'), 
            
                                $this->reported
            
                            )
            
                        ));
            
            
            
                        return $this->display(__FILE__, 'commentsalert.tpl');
            
                    }
            
                }
            
            
            
                public function ajaxUpdateCommentsInfo()
            
                {
            
                    Configuration::updateValue('COMMENTS_ALERT_LAST_AWAITING', $this->waiting_approval);
            
                    Configuration::updateValue('COMMENTS_ALERT_LAST_REPORT', $this->reported);
            
                    die(Tools::jsonEncode(array(
            
                        'waiting_approval' => $this->waiting_approval,
            
                        'reported' => $this->reported
            
                    )));
            
                }
            
            }


  • Le module n'était pas installé, ce qui explique l'erreur, car même si tu as mis une dépendance, on se rend compte que cela ne prend pas en compte toutes les possibilités.



  • Avec le nouveau code la dépendance sera réelle.
    Il faut que je regarde comment ils ont codé le dependencies...



  • Le contrôle ne doit se faire que lors de l'installation à mon avis.



  • Oui, mais cette partie n'est pas gérée lors de l'install/upgrade du CMS.
    Je viens d'ajouter un contrôle dans le constructeur de Module.php et si la dépendance n'est pas installée, le module sera lui-même désinstallé.


Se connecter pour répondre