Evite que la migration se fasse plusieurs fois et fuck up les sommes
This commit is contained in:
parent
d0543cd744
commit
5a4fede36d
56
upgrade.php
56
upgrade.php
|
@ -1,11 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
use Garradin\Plugin\Facturation\Facture;
|
||||
|
||||
define('DEVIS', 0);
|
||||
define('FACT', 1);
|
||||
define('CERFA', 2);
|
||||
define('COTIS', 3);
|
||||
|
||||
$db = DB::getInstance();
|
||||
$facture = new Facture;
|
||||
$infos = $plugin->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,8 +86,11 @@ EOT
|
|||
// 0.6.0 - Migration Facturation\Config vers la table plugins
|
||||
if (version_compare($infos->version, '0.6.0', '<'))
|
||||
{
|
||||
// SQL -> total integer
|
||||
$db->exec(<<<EOT
|
||||
$r = $db->first('SELECT id, total FROM plugin_facturation_factures;');
|
||||
if (strpos($r->total,'.'))
|
||||
{
|
||||
// SQL -> total integer
|
||||
$db->exec(<<<EOT
|
||||
|
||||
CREATE TABLE IF NOT EXISTS plugin_facturation_factures_tmp
|
||||
(
|
||||
|
@ -99,27 +108,34 @@ if (version_compare($infos->version, '0.6.0', '<'))
|
|||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
$contenu[] = ['designation' => $content['designation'],
|
||||
'prix' => (int) ($content['prix'] * 100) ];
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue