public function run($context) { $stock_factory = new Stock(); $stocks = $stock_factory->find_by_query('SELECT * FROM `creso_titoli` ' . 'LEFT JOIN `creso_obbligazioni` ON `creso_titoli`.`isin` = `creso_obbligazioni`.`isin` ' . 'WHERE ' . "`creso_titoli`.`tipo` = 'obbligazione' " . 'AND ' . "`creso_obbligazioni`.`emissione` = '0000-00-00' " . 'AND ' . '`creso_titoli`.`attivo` = 1 ' . 'LIMIT 1500'); $updated_count = 0; foreach ($stocks as $stock) { $bond = new Bond(); $bond->find_by_id($stock->isin); $bond->emissione = isin2emissione_ariva($stock->isin); if ($bond->emissione != '0000-00-00') { $bond->save(); $updated_count++; } } printf("%s updated %d bonds\n", get_called_class(), $updated_count); }
<?php ini_set('max_execution_time', 3000); require_once dirname(__FILE__) . "/lib.inc.php"; require_once dirname(__FILE__) . "/../include/db.inc.php"; require_once dirname(__FILE__) . "/../include/" . DB_ADAPTER . "_adapter.php"; require_once dirname(__FILE__) . "/../models/preference.php"; require_once dirname(__FILE__) . "/../models/bond.php"; require_once dirname(__FILE__) . "/../models/stock.php"; date_default_timezone_set('Europe/Rome'); echo "Reading preferences..."; $preference_factory = new Preference(); $preferences = $preference_factory->find_all()[0]; // print_r($preferences); echo "done\n"; $stock_factory = new Stock(); $stocks = $stock_factory->find_by_query('SELECT * FROM `creso_titoli` ' . 'LEFT JOIN `creso_obbligazioni` ON `creso_titoli`.`isin` = `creso_obbligazioni`.`isin` ' . 'WHERE ' . "`creso_titoli`.`tipo` = 'obbligazione' " . 'AND ' . "`creso_obbligazioni`.`emissione` = '0000-00-00' " . 'AND ' . '`creso_titoli`.`attivo` = 1 ' . 'LIMIT 1500'); printf("%d bonds found\n", count($stocks)); $updated_count = 0; foreach ($stocks as $stock) { // print_r($stock); $bond = new Bond(); $bond->find_by_id($stock->isin); // print_r($bond); $bond->emissione = isin2emissione_ariva($stock->isin); print_r($bond); if ($bond->emissione != '0000-00-00') { $bond->save(); $updated_count++; } } printf("%d updated bonds\n", $updated_count);