Evite que la migration se fasse plusieurs fois et fuck up les sommes

This commit is contained in:
Noizette 2021-11-06 02:47:19 +01:00
parent d0543cd744
commit 5a4fede36d
1 changed files with 38 additions and 22 deletions

View File

@ -1,11 +1,17 @@
<?php <?php
namespace Garradin; namespace Garradin;
use Garradin\Plugin\Facturation\Facture;
define('DEVIS', 0);
define('FACT', 1);
define('CERFA', 2);
define('COTIS', 3);
$db = DB::getInstance(); $db = DB::getInstance();
$facture = new Facture;
$infos = $plugin->getInfos(); $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 // 0.2.0 - Stock le contenu en json plutôt qu'en serialized
if (version_compare($infos->version, '0.2.0', '<')) if (version_compare($infos->version, '0.2.0', '<'))
@ -80,8 +86,11 @@ EOT
// 0.6.0 - Migration Facturation\Config vers la table plugins // 0.6.0 - Migration Facturation\Config vers la table plugins
if (version_compare($infos->version, '0.6.0', '<')) if (version_compare($infos->version, '0.6.0', '<'))
{ {
// SQL -> total integer $r = $db->first('SELECT id, total FROM plugin_facturation_factures;');
$db->exec(<<<EOT if (strpos($r->total,'.'))
{
// SQL -> total integer
$db->exec(<<<EOT
CREATE TABLE IF NOT EXISTS plugin_facturation_factures_tmp 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 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; DROP TABLE plugin_facturation_factures;
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures; ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
EOT 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) $contenu[] = ['designation' => $content['designation'],
{ 'prix' => (int) ($content['prix'] * 100) ];
foreach($f->contenu as $line => $content) }
{
$contenu[] = ['designation' => $content['designation'], $f->contenu = $contenu;
'prix' => (int) ($content['prix'] * 100) ]; $data = (array) $f;
} $data['total'] = (int) ($data['total'] * 100);
$f->contenu = $contenu; unset($data['id']);
$data = (array) $f; unset($data['date_emission']);
unset($data['id']); unset($data['date_echeance']);
unset($data['date_emission']); $facture->edit($f->id, $data);
unset($data['date_echeance']); unset($contenu);
var_dump($data); }
$facture->edit($f->id, $data);
unset($contenu);
} }
} }