Newscoop\Entity\Repository\ArticleDatetimeRepository::update PHP Метод

update() публичный Метод

Update entry by id
public update ( integer $id, array $timeSet, integer $articleId = null, string $fieldName = null, string $recurring = null, $otherInfo = null )
$id integer
$timeSet array
$articleId integer
$fieldName string
$recurring string
    public function update($id, $timeSet, $articleId = null, $fieldName = null, $recurring = null, $otherInfo = null)
    {
        $em = $this->getEntityManager();
        $entry = $this->find($id);
        if (!$entry) {
            return false;
        }
        if (is_null($articleId)) {
            $articleId = $entry->getArticleId();
        }
        if (is_null($fieldName)) {
            $fieldName = $entry->getFieldName();
        }
        $insertValues = $this->buildInsertValues($timeSet, $recurring);
        $em->getConnection()->beginTransaction();
        try {
            $em->remove($entry);
            foreach ($insertValues as $dateValue) {
                foreach (array_merge(array($dateValue), $dateValue->getSpawns()) as $dateValue) {
                    $articleDatetime = new ArticleDatetime();
                    $articleDatetime->setValues($dateValue, $articleId, $fieldName, $entry->getArticleType(), $otherInfo);
                    $em->persist($articleDatetime);
                }
            }
            $em->flush();
            $em->getConnection()->commit();
        } catch (\Exception $e) {
            $em->getConnection()->rollback();
            $em->close();
            return $e;
        }
    }