$t->diag('Add a new charge');
$car = new OppCarica();
$car->setId(999999);
$car->setOppPolitico($pol);
$car->setTipoCaricaId(2);
$car->setCarica('Ministro dell\'abolizione dei beni Inutili');
$car->setDataInizio('2008-10-10');
$car->save();
$pol_related_news = getRelatedNews($pol);
$n_pol_related_news = count($pol_related_news);
$t->diag("related_news: " . $n_pol_related_news);
$t->ok($n_pol_related_news == 1, 'One news related to the politician');
dumpNews($t, "news related to the politician", $pol_related_news);
$t->diag('Add a group to the charge');
$gruppo = OppGruppoPeer::retrieveByPK(1);
$car_gruppo = new OppCaricaHasGruppo();
$car_gruppo->setOppCarica($car);
$car_gruppo->setOppGruppo($gruppo);
$car_gruppo->setDataInizio('2008-08-20');
$car_gruppo->save();
$pol_related_news = getRelatedNews($pol);
$n_pol_related_news = count($pol_related_news);
$t->ok($n_pol_related_news == 2, 'Two news related to the politician');
dumpNews($t, "news related to the politician", $pol_related_news);
$t->diag('Add a first-signer, at the presentation date');
$firma = new OppCaricaHasAtto();
$firma->setTipo('P');
$firma->setOppCarica($car);
$firma->setOppAtto($obj);
$firma->setData($obj->getDataPres());
$firma->save();
<?php

define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'fe');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', true);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
sfContext::getInstance();
print "Fetching data... \n";
$cariche = OppCaricaPeer::doSelect(new Criteria());
foreach ($cariche as $carica) {
    $c = new Criteria();
    $c->add(OppGruppoPeer::NOME, $carica->getGruppo(), Criteria::EQUAL);
    $gruppo = OppGruppoPeer::doSelectOne($c);
    if ($gruppo != null) {
        $carica_gruppo = new OppCaricaHasGruppo();
        $carica_gruppo->setCaricaId($carica->getId());
        $carica_gruppo->setGruppoId($gruppo->getId());
        $carica_gruppo->setDataInizio($carica->getDataInizio());
        $carica_gruppo->setDataFine($carica->getDataFine());
        $carica_gruppo->save();
    } else {
        echo "carica {$carica->getId}() gruppo non trovato\n";
    }
}
print "done.\n";