Skip to content

Commit

Permalink
Delete product image instead of set remove=1
Browse files Browse the repository at this point in the history
  • Loading branch information
trecouvr committed Sep 13, 2013
1 parent 0aa1bbf commit 47b376f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
16 changes: 6 additions & 10 deletions src/Payutc/Bom/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ public static function delete($id, $fun_id) {
}

// start transaction
Dbal::beginTransaction();
$conn = Dbal::conn();
$conn->beginTransaction();

try {
// 2. remove article
Expand All @@ -279,19 +280,14 @@ public static function delete($id, $fun_id) {
->setParameter('id', $id);
$qb->execute();

// 4. remove image
$qb = Dbal::createQueryBuilder();
$qb->update('ts_image_img', 'img')
->where('img_id = :id')
->set('img_removed', 1)
->setParameter('id', $don['img_id']);
$qb->execute();
// 4. delete image
$conn->delete('ts_image_img', array('img_id' => $don['img_id']));

// commit
Dbal::commit();
$conn->commit();
}
catch (Exception $e) {
Dbal::rollback();
$conn->rollback();
return array("error"=>400, "error_msg"=>"Erreur lors de la suppression de l'objet $id.");
}

Expand Down
7 changes: 3 additions & 4 deletions tests/ProductRwdbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,12 @@ public function testDelete() {
}
// check the image has been removed too
$qb = Dbal::createQueryBuilder();
$q = $qb->select('img_removed')
$q = $qb->select('count(*) as count')
->from('ts_image_img', 'img')
->where('img_id = :id')
->setParameter('id', $img_id);
$img = $q->execute()->fetch();
$this->assertNotNull($img);
$this->assertEquals(1, $img['img_removed']);
$res = $q->execute()->fetch();
$this->assertEquals(0, $res['count']);
}
}

Expand Down

0 comments on commit 47b376f

Please sign in to comment.