public function updateAction($id) { return ProductsService::update($id, $this->request->getRawBody()); }
static function update($composition, $img = "", $groupImgs) { if ($composition->id === null) { return false; } $pdo = PDOBuilder::getPDO(); $newTransaction = !$pdo->inTransaction(); if ($newTransaction) { $pdo->beginTransaction(); } // Update product if (!ProductsService::update($composition, $img)) { if ($newTransaction) { $pdo->rollback(); } return false; } // Delete current subgroups $srv = new SubgroupsService($composition->id); if (!$srv->deleteAll()) { if ($newTransaction) { $pdo->rollback(); } return false; } // Create subgroups if (!$srv->create($composition->groups, $groupImgs)) { if ($newTransaction) { $pdo->rollback(); } return false; } else { if ($newTransaction) { $pdo->commit(); } return true; } }