@inheritdoc

@throws DuplicateVersionException
194774
public function append(EventStreamInterface $eventStream)
    {
        /** @var $event Event */
        foreach ($eventStream as $event) {
            $version = $event->getVersion();
            $id = $event->getId();

            if (!isset($this->store[$id])) {
                $this->store[$id] = [];
            }

            if (isset($this->store[$id][$version])) {
                throw new DuplicateVersionException($version);
            }

            $this->store[$id][$version] = $event;
        }
    }
97026
public static function getVersionForNumber(int $versionNumber) : self
    {
        if ($versionNumber < 1 || $versionNumber > 40) {
            throw new InvalidArgumentException('Version number must be between 1 and 40');
        }

        return self::versions()[$versionNumber - 1];
    }
1103502
public function withVersion(int $version): self
    {
        $obj = clone $this;
        $obj->_version = $version;
        return $obj;
    }
1325118
private function resolveVersion($version)
    {
        if (isset($this->aliases[$version])) {
            $version = $this->aliases[$version];

            return $version;
        }

        return $version;
    }
693123
public function insertVersion(VersionInfo $versionInfo, array $fields)
    {
        /** @var $q \eZ\Publish\Core\Persistence\Database\InsertQuery */
        $q = $this->dbHandler->createInsertQuery();
        $q->insertInto(
            $this->dbHandler->quoteTable('ezcontentobject_version')
        )->set(
            $this->dbHandler->quoteColumn('id'),
            $this->dbHandler->getAutoIncrementValue('ezcontentobject_version', 'id')
        )->set(
            $this->dbHandler->quoteColumn('version'),
            $q->bindValue($versionInfo->versionNo, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('modified'),
            $q->bindValue($versionInfo->modificationDate, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('creator_id'),
            $q->bindValue($versionInfo->creatorId, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('created'),
            $q->bindValue($versionInfo->creationDate, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('status'),
            $q->bindValue($versionInfo->status, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('initial_language_id'),
            $q->bindValue(
                $this->languageHandler->loadByLanguageCode($versionInfo->initialLanguageCode)->id,
                null,
                \PDO::PARAM_INT
            )
        )->set(
            $this->dbHandler->quoteColumn('contentobject_id'),
            $q->bindValue($versionInfo->contentInfo->id, null, \PDO::PARAM_INT)
        )->set(
            // As described in field mapping document
            $this->dbHandler->quoteColumn('workflow_event_pos'),
            $q->bindValue(0, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('language_mask'),
            $q->bindValue(
                $this->generateLanguageMask(
                    $fields,
                    $versionInfo->initialLanguageCode,
                    $versionInfo->contentInfo->alwaysAvailable
                ),
                null,
                \PDO::PARAM_INT
            )
        );

        $q->prepare()->execute();

        return $this->dbHandler->lastInsertId(
            $this->dbHandler->getSequenceName('ezcontentobject_version', 'id')
        );
    }
1323259
public function duplicate($id)
    {
        // Find the source item
        $src = $this->findOrFail($id);
        if (empty($src->cloneable)) {
            return App::abort(404);
        }

        // Duplicate using Bkwld\Cloner
        $new = $src->duplicate();

        // Don't make duplicates public
        if (array_key_exists('public', $new->getAttributes())) {
            $this->public = 0;
        }

        // If there is a name or title field, append " copy" to it.  Use "original"
        // to avoid mutators.
        if ($name = $new->getOriginal('name')) {
            $new->setAttribute('name', $name.' copy');
        } elseif ($title = $new->getOriginal('title')) {
            $new->setAttribute('title', $title.' copy');
        }

        // Set localization options on new instance
        if ($locale = request('locale')) {
            $new->locale = $locale;
            if (isset($src->locale_group)) {
                $new->locale_group = $src->locale_group;
            }
        }

        // Save any changes that were made
        $new->save();

        // Save the new record and redirect to its edit view
        return Redirect::to(DecoyURL::relative('edit', $new->getKey()))
            ->with('success', $this->successMessage($src, 'duplicated'));
    }
396013
public function onDuplicateUpdate($fields)
    {
        if(is_array($fields) && count($fields) != 0) {
            foreach($fields as $field => $value) {
                $array[] = " `$field` = ".((is_string($value) ? "'$value'" : $value));
            }
            $this->duplicateUpdate = " ON DUPLICATE KEY UPDATE ".implode(" $glue", $array);
        }
        elseif(is_string($fields) && trim($fields) != '') {
            $fields = trim($fields);
            //$where = trim($where, 'WHERE ');
            //$where = rtrim($where);
            $this->duplicateUpdate = ' ON DUPLICATE KEY UPDATE '.$fields;
        }
        return $this;
    }
504083
public function validateVersionTable(EntityDefinition $entityMetadata)
    {
        $columnNames = [];
        $countPrimaryKeys = 0;
        $versionPrimaryKey = false;

        // get column names
        foreach ($entityMetadata['table']['columns'] as $column) {
            $columnNames[] = $column['name'];
        }

        if (! in_array('latest_version', $columnNames)) {
            throw new DomainException('@Versionable annotation defined in class ' . $entityMetadata['class'] . ' requires a $latestVersion column property.');
        }

        $columnNames = [];

        // get version column names
        foreach ($entityMetadata['versionTable']['columns'] as $column) {
            $columnNames[] = $column['name'];
            if (! empty($column['primary'])) {
                $countPrimaryKeys++;
            }
            if (! empty($column['primary']) && $column['name'] == 'version') {
                $versionPrimaryKey = true;
            }
        }

        if (! in_array('version', $columnNames) || ! $versionPrimaryKey) {
            throw new DomainException('@Versionable annotation defined in class ' . $entityMetadata['class'] . ' requires a $version property column, which is a primary key.');
        }
        if ($countPrimaryKeys > 2) {
            throw new DomainException('No more than 2 primary keys are allowed for version table in class ' . $entityMetadata['class'] . '.');
        }
    }
531325
protected function isVersionedKey($key, array $versionedKeys)
    {
        $segments = explode(".",$key);

        if (count($segments) > 2) {
            throw new Exception("Key '".$key."' has too many fractions.");
        }

        if (count($segments) == 1 && in_array($segments[0], $versionedKeys)) {
            return $segments[0];
        }

        if (count($segments) == 2 && $segments[0] == $this->model->getVersionTable() && in_array($segments[1], $versionedKeys)) {
            return $segments[1];
        }

        return null;
    }
823023
public function getOneVersion($versionNumber, $con = null)
    {
        return ChildDealerBrandVersionQuery::create()
            ->filterByDealerBrand($this)
            ->filterByVersion($versionNumber)
            ->findOne($con);
    }
821902
public function duplicate(ContentInterface $content)
    {
        //duplicate content
        $duplicatedContent = clone $content;
        $duplicatedContent->setTitle(sprintf("%s copy %s", $duplicatedContent->getTitle(), date('r')));
        $duplicatedContent->setSlug(null);
        $duplicatedContent->setActive(false);
        $duplicatedContent->setCreatedAt(new \DateTime());

        //get valueset to clone
        if (null !== $valueset = $content->getValueSet()) {
            //clone valueset
            $duplicatedValueset = clone $valueset;

            $this->detachAndPersist($duplicatedValueset);
            $duplicatedContent->setValueSet($duplicatedValueset);
        }

        $duplicatedContent->setBlocks(null);
        $this->detachAndPersist($duplicatedContent);

        if ($valueset) {
            //iterate values, clone each and assign duplicate valueset to it
            foreach ($valueset->getValues() as $value) {

                //skip empty attributes
                if (is_null($value->getId())) continue;

                $duplicatedValue = clone ($value);
                $duplicatedValue->setValueSet($duplicatedValueset);

                $this->detachAndPersist($duplicatedValue);
            }
        }
        $this->em->flush();

        return $duplicatedContent;
    }
721130
public function getVersions(VersionableInterface $resource)
    {
        $query = $this->_em->createQuery(
            'SELECT v FROM ResourceVersion v INDEX BY v.version '.
            'WHERE v.resourceName = ?1 AND v.resourceId = ?2 ORDER BY v.version DESC');
        $query->setParameter(1, get_class($resource));
        $query->setParameter(2, $resource->getResourceId());

        return $query->getResult();
    }
253399
public function setVersion($version)
    {
        if ($version == self::VERSION_3 || $version == self::VERSION_3_1_1) {
            $this->version = $version;
        } else {
            throw new Exception('Invalid version');
        }
    }
293275
public function getVersion($versionNumber): Version
    {
        $versionNumber = $versionNumber instanceof VersionNumber
            ? $versionNumber
            : VersionNumber::fromValue($versionNumber);

        foreach ($this->listVersions() as $version) {
            if ($version->versionNumber()->equalsTo($versionNumber)) {
                return $version;
            }
        }

        throw VersionNotFound::withVersionNumber($versionNumber);
    }
1232678
public function countDealerFolderVersions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collDealerFolderVersionsPartial && !$this->isNew();
        if (null === $this->collDealerFolderVersions || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collDealerFolderVersions) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getDealerFolderVersions());
            }

            $query = ChildDealerFolderVersionQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterByDealerFolder($this)
                ->count($con);
        }

        return count($this->collDealerFolderVersions);
    }
1054141
public function getOneVersion($versionNumber, $con = null)
    {
        return ChildIndexEngineIndexVersionQuery::create()
            ->filterByIndexEngineIndex($this)
            ->filterByVersion($versionNumber)
            ->findOne($con);
    }
57710
public function set(string $version): VersionInterface
    {
        $matches = [];
        $numbers = [];

        if (preg_match($this->regex, $version, $matches)) {
            $numbers = $this->mapMatches($matches);
        }

        if (empty($numbers)) {
            return new Version('0');
        }

        $major = (array_key_exists('major', $numbers) ? $numbers['major'] : '0');
        $minor = (array_key_exists('minor', $numbers) ? $numbers['minor'] : '0');

        if (array_key_exists('micro', $numbers)) {
            $micro      = $numbers['micro'];
            $patch      = (array_key_exists('patch', $numbers) ? $numbers['patch'] : null);
            $micropatch = (array_key_exists('micropatch', $numbers) ? $numbers['micropatch'] : null);
        } else {
            $micro      = '0';
            $patch      = null;
            $micropatch = null;
        }

        $stability = (array_key_exists('stability', $numbers)) ? $numbers['stability'] : null;

        if (null === $stability || 0 === mb_strlen($stability)) {
            $stability = 'stable';
        }

        $stability = mb_strtolower($stability);
        switch ($stability) {
            case 'rc':
                $stability = 'RC';

                break;
            case 'patch':
            case 'pl':
            case 'p':
                $stability = 'patch';

                break;
            case 'beta':
            case 'b':
                $stability = 'beta';

                break;
            case 'alpha':
            case 'a':
                $stability = 'alpha';

                break;
            case 'dev':
            case 'd':
                $stability = 'dev';

                break;
        }

        $build = (array_key_exists('build', $numbers)) ? $numbers['build'] : null;

        return new Version($major, $minor, $micro, $patch, $micropatch, $stability, $build);
    }