diff --git a/db/migrations/20181213125806_add_parent_field.php b/db/migrations/20181213125806_add_parent_field.php index 4b0061510792996a40bcef142b904c91d53cacb8..c962bcb276ca53363d5ea5eaf08833865bf64fb5 100644 --- a/db/migrations/20181213125806_add_parent_field.php +++ b/db/migrations/20181213125806_add_parent_field.php @@ -33,10 +33,8 @@ class AddParentField extends AbstractMigration public function change() { $table = $this->table('contreparties'); - if (!$table->hasColumn('parent')) { - $table->addColumn('parent', 'integer'); - $table->update(); - } + $table->addColumn('parent', 'integer'); + $table->update(); $builder = $this->getQueryBuilder(); $stmt = $builder->update('contreparties') ->set('parent', 'id') diff --git a/src/LQDN/Handler/UserHandler.php b/src/LQDN/Handler/UserHandler.php index e9a4cbbd51ea5098eddaa66260401571f6c63485..0ae0a0de1422efdba87c394d231bdce807862a3e 100644 --- a/src/LQDN/Handler/UserHandler.php +++ b/src/LQDN/Handler/UserHandler.php @@ -106,7 +106,7 @@ class UserHandler // quoi = 'pibag' somme = 50 // quoi = 'piplome' somme = 30 $spent = $this->connection->executeQuery( - "SELECT sum(IF(quoi = 'hoodie',250,0)) + sum(IF(quoi = 'pishirt', 100, 0)) + sum(IF(quoi = 'pibag', 50, 0)) + sum(IF(quoi = 'piplome', 30, 0)) AS spent FROM contreparties WHERE user_id = :user_id AND contreparties.id = contreparties.parent", + "SELECT sum(IF(quoi = 'hoodie',250,0)) + sum(IF(quoi = 'pishirt', 100, 0)) + sum(IF(quoi = 'pibag', 50, 0)) + sum(IF(quoi = 'piplome', 30, 0)) AS spent FROM contreparties WHERE user_id = :user_id AND id = parent", [ 'user_id' => $user_id] )->fetchAll(\PDO::FETCH_COLUMN)[0]; $this->connection->executeUpdate('UPDATE users SET total = :total, cumul = :cumul WHERE id = :user_id', ['total' => (int) $total, 'cumul' => (int) $total - (int) $spent, 'user_id' => $user_id]);