thirtybees icon indicating copy to clipboard operation
thirtybees copied to clipboard

List of operating systems is outdated

Open musicpanda opened this issue 3 years ago • 3 comments

In classes/guest.php there is a list of operating systems

    protected function getOs($userAgent)
    {
        $osArray = [
            'Windows 8'     => 'Windows NT 6.2',
            'Windows 7'     => 'Windows NT 6.1',
            'Windows Vista' => 'Windows NT 6.0',
            'Windows XP'    => 'Windows NT 5',
            'MacOsX'        => 'Mac OS X',
            'Android'       => 'Android',
            'Linux'         => 'X11',
        ];

        foreach ($osArray as $k => $value) {
            if (strstr($userAgent, $value)) {
                $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(
                    (new DbQuery())
                        ->select('`id_operating_system`')
                        ->from('operating_system', 'os')
                        ->where('os.`name` = \''.pSQL($k).'\'')
                );

                return $result['id_operating_system'];  /* this is line 216 */
            }
        }

The absence of modern operating systems has as a result that this function produces lots of errors of the type PHP Notice: Trying to access array offset on value of type bool in /home/public/sites/www.website.com/classes/Guest.php on line 216

musicpanda avatar Nov 10 '22 17:11 musicpanda

Your PHP notice issue will be probably caused by data inconsistency. Table operating_system should contain rows for all the $osArray: https://github.com/thirtybees/thirtybees/blob/9e8002f786ae10e0b36187871ea70245bb748f82/install-dev/data/xml/operating_system.xml.

If database table contained these rows, then the row would be found, and $result would be array. I believe that in your case the database table is empty.

Anyway, your complaint is totally valid -- the $osArray should be updated to reflect current operating systems.

getdatakick avatar Nov 10 '22 18:11 getdatakick

In my rather old shop this table indeed contained only four rows.

musicpanda avatar Nov 10 '22 19:11 musicpanda

In Prestashop 1.7.8 it looks so: protected function getOs($userAgent) { $osArray = [ 'Windows 10' => 'Windows NT 10', 'Windows 8.1' => 'Windows NT 6.3', 'Windows 8' => 'Windows NT 6.2', 'Windows 7' => 'Windows NT 6.1', 'Windows Vista' => 'Windows NT 6.0', 'Windows XP' => 'Windows NT 5', 'MacOsX' => 'Mac OS X', 'Android' => 'Android', 'Linux' => 'X11', ];

musicpanda avatar Nov 11 '22 10:11 musicpanda