diff --git a/upgrade.php b/upgrade.php index c3a03a5..d264524 100644 --- a/upgrade.php +++ b/upgrade.php @@ -1,11 +1,17 @@ getInfos(); -// Pl il y avait cette ligne ? -// $db->import(dirname(__FILE__) . "/data/schema.sql"); + // 0.2.0 - Stock le contenu en json plutôt qu'en serialized if (version_compare($infos->version, '0.2.0', '<')) @@ -80,9 +86,12 @@ EOT // 0.6.0 - Migration Facturation\Config vers la table plugins if (version_compare($infos->version, '0.6.0', '<')) { - // SQL -> total integer - $db->exec(<<first('SELECT id, total FROM plugin_facturation_factures;'); + if (strpos($r->total,'.')) + { + // SQL -> total integer + $db->exec(<<version, '0.6.0', '<')) contenu TEXT NOT NULL, total INTEGER DEFAULT 0 ); - - INSERT INTO plugin_facturation_factures_tmp SELECT id, type_facture, numero, receveur_membre, receveur_id, date_emission, date_echeance, reglee, archivee, moyen_paiement, contenu, CAST(total * 100 as INT) as total FROM plugin_facturation_factures; + + INSERT INTO plugin_facturation_factures_tmp SELECT * FROM plugin_facturation_factures; DROP TABLE plugin_facturation_factures; ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures; EOT ); + + foreach($factures = $facture->listAll() as $k=>$f) + { + foreach($f->contenu as $line => $content) + { + // Petit bug qui peut arriver avec des contenus mal enregistrés en db + if (is_int($content)) + { + continue; + } + $contenu[] = ['designation' => $content['designation'], + 'prix' => (int) ($content['prix'] * 100) ]; + } - foreach($factures = $facture->listAll() as $k=>$f) - { - foreach($f->contenu as $line => $content) - { - $contenu[] = ['designation' => $content['designation'], - 'prix' => (int) ($content['prix'] * 100) ]; - } - $f->contenu = $contenu; - $data = (array) $f; - unset($data['id']); - unset($data['date_emission']); - unset($data['date_echeance']); - var_dump($data); - $facture->edit($f->id, $data); - unset($contenu); + $f->contenu = $contenu; + $data = (array) $f; + $data['total'] = (int) ($data['total'] * 100); + unset($data['id']); + unset($data['date_emission']); + unset($data['date_echeance']); + $facture->edit($f->id, $data); + unset($contenu); + } } } \ No newline at end of file