/**
 * Importa dei ddl a partire da un file yaml
 */
function run_opp_import_ddl_from_yaml($task, $args, $options)
{
    static $loaded;
    // load application context
    if (!$loaded) {
        _loader();
    }
    $dry_run = false;
    if (array_key_exists('dry-run', $options)) {
        $dry_run = true;
    }
    if (array_key_exists('yaml-file', $options)) {
        $yaml_file = strtolower($options['yaml-file']);
    } else {
        throw new Exception("Specificare il file contenente i dati dei ddl con l'opzione --yaml-file=FILE_COMPLETE_PATH");
    }
    if (array_key_exists('leg', $options)) {
        $leg = strtolower($options['leg']);
    } else {
        throw new Exception("Specificare la legislatura con l'opzione --leg=LEGISLATURA");
    }
    echo "memory usage: " . memory_get_usage() . "\n";
    $start_time = time();
    $msg = sprintf("import ddl da {$yaml_file}\n");
    echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true));
    if (file_exists($yaml_file)) {
        $ddls = sfYaml::Load($yaml_file);
    } else {
        throw new Exception("Impossibile trovare il file {$yaml_file}");
    }
    foreach ($ddls as $key => $ddl) {
        $atto = new OppAtto();
        $atto->setLegislatura($leg);
        $atto->setParlamentoId($ddl['parlamento_id']);
        $atto->setRamo(strtoupper($ddl['ramo']));
        $atto->setNumfase($ddl['numfase']);
        $atto->setTipoAttoId(1);
        $atto->setDataPres($ddl['presentazione_date']);
        $atto->setDataAgg($ddl['update_date']);
        $atto->setTitolo($ddl['titolo']);
        $atto->setIniziativa($ddl['iniziativa']);
        if ($dry_run) {
            var_dump($ddl);
        } else {
            $atto->save();
            $msg = sprintf("atto %s.%s aggiunto - parlamento_id:%d, opp_id:%d\n", $atto->getRamo(), $atto->getNumfase(), $atto->getParlamentoId(), $atto->getId());
            echo pakeColor::colorize($msg, array('fg' => 'green', 'bold' => false));
        }
        unset($atto);
    }
    $msg = sprintf("%d atti elaborati\n", count($ddls));
    echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true));
    $msg = sprintf(" [%4d sec] [%10d bytes]\n", time() - $start_time, memory_get_usage());
    echo pakeColor::colorize($msg, array('fg' => 'red', 'bold' => false));
}
foreach ($existing_records as $rec) {
    $t->diag('Cleaning record ' . get_class($rec) . "(" . $rec->getId() . ")");
    $rec->delete();
}
$c = new Criteria();
$c->add(OppPoliticoPeer::ID, 999999);
$existing_records = OppPoliticoPeer::doSelect($c);
foreach ($existing_records as $rec) {
    $t->diag('Cleaning record ' . get_class($rec) . "(" . $rec->getId() . ")");
    $rec->delete();
}
$t->diag('Create the test act object');
$obj = new OppAtto();
$obj->setTipoAttoId(1);
$obj->setParlamentoId(999999);
$obj->setRamo('S');
$obj->setNumFase(914);
$obj->setDataPres('2008-11-01');
$obj->setDescrizione("Una descrizione di prova");
$obj->save();
$related_news = getRelatedNews($obj);
$n_related_news = count($related_news);
$first_news = $related_news[0];
$t->ok($n_related_news == 1, 'One news related to the act was generated');
dumpNews($t, "news related to the act", $related_news);
$t->diag('Create a non-final votation: two more news expected (group and detail)');
$vot = OppVotazionePeer::retrieveByPK(9900);
$vot_att = new OppVotazioneHasAtto();
$vot_att->setOppVotazione($vot);
$vot_att->setOppAtto($obj);
$vot_att->save();
Ejemplo n.º 3
0
<?php

define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', false);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
$ddls = OppDdlPeer::doSelect(new Criteria());
foreach ($ddls as $ddl) {
    $atto = new OppAtto();
    $atto->setId($ddl->getId());
    $atto->setParlamentoId($ddl->getParlamentoId());
    $atto->setTipoAttoId($ddl->getTipo());
    $atto->setRamo($ddl->getRamo());
    $atto->setNumfase($ddl->getNumfase());
    $atto->setLegislatura($ddl->getLegislatura());
    $atto->setDataPres($ddl->getDataPres());
    $atto->setDataAgg($ddl->getDataAgg());
    $atto->setTitolo($ddl->getTitolo());
    $atto->setIniziativa($ddl->getIniziativa());
    $atto->setCompleto($ddl->getCompleto());
    $atto->setDescrizione($ddl->getDescrizione());
    $atto->setSeduta($ddl->getSeduta());
    $atto->setIter($ddl->getIter());
    $atto->setDataIter($ddl->getDataIter());
    $atto->save();
    print "atto: " . $atto->getId() . "...\n";
}
print "done.\n";