<?php

//This script will update all records in the consoleinfo table
define('FS_ROOT', realpath(dirname(__FILE__)));
require_once FS_ROOT . "/../../www/config.php";
require_once FS_ROOT . "/../../www/lib/framework/db.php";
require_once FS_ROOT . "/../../www/lib/console.php";
$console = new Console(true);
$db = new Db();
$res = $db->queryDirect(sprintf("SELECT searchname, ID from releases where consoleinfoID IS NULL and categoryID in ( select ID from category where parentID = %d ) ORDER BY id DESC LIMIT %d", Category::CAT_PARENT_GAME, Console::NUMTOPROCESSPERTIME));
if ($res != null) {
    while ($arr = $db->getAssocArray($res)) {
        $conInfo = $console->parseTitle($arr['searchname']);
        if ($conInfo !== false) {
            echo 'Searching ' . $conInfo['release'] . '<br />';
            $con = $console->updateConsoleInfo($conInfo);
            if ($con !== false) {
                print_r($con);
            } else {
                echo 'Console not found';
            }
        }
    }
}