oroinc / platform

Main OroPlatform package with core functionality.
MIT License
629 stars 351 forks source link

Wrong requirements report for image processor libs #1068

Open joancafom opened 3 years ago

joancafom commented 3 years ago

Summary
When using the command php bin/console oro:check-requirements -vv to check the configuration of your current Oro installation, the application produces the following report for Optional Recommendations:

Steps to reproduce

$ php bin/console oro:check-requirements -vv
...
+---------+------------------------------------------------------------------------------------------------------------------+
| Check   | Optional recommendations                                                                                         |
+---------+------------------------------------------------------------------------------------------------------------------+
| OK      | Current version 63.1 of the ICU library should meet the requirements                                             |
| OK      | SOAP extension should be installed (API calls)                                                                   |
| OK      | Tidy extension should be installed to make sure that any HTML is correctly converted into a text representation. |
| WARNING | Disable Phar extension to reduce the risk of PHP unserialization vulnerability.                                  |
| OK      | IMAP extension should be installed for valid email processing on IMAP sync.                                      |
| OK      | PHP-DOM and PHP-XML modules should be installed                                                                  |
| OK      | mb_strlen() should be available                                                                                  |
| OK      | utf8_decode() should be available                                                                                |
| OK      | filter_var() should be available                                                                                 |
| OK      | posix_isatty() should be available                                                                               |
| OK      | a PHP accelerator should be installed                                                                            |
| WARNING | Library `jpegoptim` should be installed                                                                          |
| WARNING | Library `pngquant` should be installed                                                                           |
| OK      | xdebug.max_nesting_level should be above 100 in php.ini                                                          |
| OK      | intl.error_level should be 0 in php.ini                                                                          |
| OK      | short_open_tag should be disabled in php.ini                                                                     |
| OK      | magic_quotes_gpc should be disabled in php.ini                                                                   |
| OK      | register_globals should be disabled in php.ini                                                                   |
| OK      | session.auto_start should be disabled in php.ini                                                                 |
| WARNING | To get the latest internationalization data upgrade the ICU system package and the intl PHP extension.           |
+---------+------------------------------------------------------------------------------------------------------------------+

However, the image processor librariesjpegoptim and pngquant are installed in the system and running a version that is supported according to documentation:

$ which jpegoptim
/usr/bin/jpegoptim

$ which pngquant
/usr/bin/pngquant

Actual Result

$ php bin/console oro:check-requirements -vv
...
+---------+------------------------------------------------------------------------------------------------------------------+
| Check   | Optional recommendations                                                                                         |
+---------+------------------------------------------------------------------------------------------------------------------+
| OK      | Current version 63.1 of the ICU library should meet the requirements                                             |
| OK      | SOAP extension should be installed (API calls)                                                                   |
| OK      | Tidy extension should be installed to make sure that any HTML is correctly converted into a text representation. |
| WARNING | Disable Phar extension to reduce the risk of PHP unserialization vulnerability.                                  |
| OK      | IMAP extension should be installed for valid email processing on IMAP sync.                                      |
| OK      | PHP-DOM and PHP-XML modules should be installed                                                                  |
| OK      | mb_strlen() should be available                                                                                  |
| OK      | utf8_decode() should be available                                                                                |
| OK      | filter_var() should be available                                                                                 |
| OK      | posix_isatty() should be available                                                                               |
| OK      | a PHP accelerator should be installed                                                                            |
| WARNING | Library `jpegoptim` should be installed                                                                          |
| WARNING | Library `pngquant` should be installed                                                                           |
| OK      | xdebug.max_nesting_level should be above 100 in php.ini                                                          |
| OK      | intl.error_level should be 0 in php.ini                                                                          |
| OK      | short_open_tag should be disabled in php.ini                                                                     |
| OK      | magic_quotes_gpc should be disabled in php.ini                                                                   |
| OK      | register_globals should be disabled in php.ini                                                                   |
| OK      | session.auto_start should be disabled in php.ini                                                                 |
| WARNING | To get the latest internationalization data upgrade the ICU system package and the intl PHP extension.           |
+---------+------------------------------------------------------------------------------------------------------------------+

Expected Result

$ php bin/console oro:check-requirements -vv
...
+---------+------------------------------------------------------------------------------------------------------------------+
| Check   | Optional recommendations                                                                                         |
+---------+------------------------------------------------------------------------------------------------------------------+
| OK      | Current version 63.1 of the ICU library should meet the requirements                                             |
| OK      | SOAP extension should be installed (API calls)                                                                   |
| OK      | Tidy extension should be installed to make sure that any HTML is correctly converted into a text representation. |
| WARNING | Disable Phar extension to reduce the risk of PHP unserialization vulnerability.                                  |
| OK      | IMAP extension should be installed for valid email processing on IMAP sync.                                      |
| OK      | PHP-DOM and PHP-XML modules should be installed                                                                  |
| OK      | mb_strlen() should be available                                                                                  |
| OK      | utf8_decode() should be available                                                                                |
| OK      | filter_var() should be available                                                                                 |
| OK      | posix_isatty() should be available                                                                               |
| OK      | a PHP accelerator should be installed                                                                            |
| OK      | Library `jpegoptim` should be installed                                                                          |
| OK      | Library `pngquant` should be installed                                                                           |
| OK      | xdebug.max_nesting_level should be above 100 in php.ini                                                          |
| OK      | intl.error_level should be 0 in php.ini                                                                          |
| OK      | short_open_tag should be disabled in php.ini                                                                     |
| OK      | magic_quotes_gpc should be disabled in php.ini                                                                   |
| OK      | register_globals should be disabled in php.ini                                                                   |
| OK      | session.auto_start should be disabled in php.ini                                                                 |
| WARNING | To get the latest internationalization data upgrade the ICU system package and the intl PHP extension.           |
+---------+------------------------------------------------------------------------------------------------------------------+

Details about your environment

Upon testing, it seems this is related to the addImageProcessorRecommendation() function. The $library var within this function incorrectly expects an array as the return value of the call to getImageProcessorLibrary(). I have modified the function myself with the following changes:

    protected function addImageProcessorRecommendation(RequirementCollection $collection, string $libraryName): void
    {
        $library = null;
        try {
+          echo("Checking library '". $this->getImageProcessorLibrary($libraryName, $this->imageProcessorConfig)."' !");
            [$library, ] = $this->getImageProcessorLibrary($libraryName, $this->imageProcessorConfig);
        } catch (ProcessorsException $exception) {
+          echo("Exception I occurred: '". $exception."' !");
            return;
        } catch (ProcessorsVersionException $exception) {
+          echo("Exception II occurred: '". $exception."' !");
            $library = $exception->getBinary();
        }

+      echo("The final value for library is: '". $library."' !");
        $collection->addRecommendation(
            null !== $library,
            sprintf('Library `%s` is installed', $libraryName),
            sprintf('Library `%s` should be installed', $libraryName)
        );
    }

And executed it again:

$ php bin/console oro:check-requirements -vv
Check system requirements
Checking library '/usr/bin/jpegoptim' !

The final value for library is: ''!

Checking library '/usr/bin/pngquant' !

The final value for library is: ''!
anyt commented 3 years ago

Thank you @joancafom, Internal ticket id #BAP-20715.