{% extends '../CommonAdmin/EditAction/EditBuilderAction.php.twig' %}

{% block orm_use %}
use \PropelException;
{% endblock %}

{% block getObject -%}
    protected function getObject($pk, $version = null)
    {
        return \{{ model }}Query::create()->findPk($pk);
    }
{% endblock %}

{% block saveObject -%}
    protected function saveObject(\{{ model }} ${{ builder.ModelClass }})
    {
        ${{ builder.ModelClass }}->save();
    }
{% endblock %}

{% block checkObjectLock -%}
{% if lock_mode is not null -%}
    $versions = $this->get('session')->get('{{ namespace_prefix }}\{{ bundle_name }}\{{ builder.BaseGeneratorName }}Edit\Versions', array());
    /* TODO: I could not find a propel equivalent of Doctrine's lock */
    if ($object->getCurrentVersion !== $versions[$pk]) {
        throw new PropelException();
    }
{%- endif %}
{% endblock %}

{% block lockException %}PropelException{% endblock %}
{% extends '../CommonAdmin/EditAction/EditBuilderAction.php.twig' %}

{% block orm_use %}
use \PropelException;
{% endblock %}

{% block getObject -%}
    protected function getObject($pk, $version = null)
    {
        return \{{ model }}Query::create()->findPk($pk);
    }
{% endblock %}

{% block saveObject -%}
    protected function saveObject(\{{ model }} ${{ builder.ModelClass }})
    {
        ${{ builder.ModelClass }}->save();
    }
{% endblock %}

{% block checkObjectLock -%}
{% if lock_mode is not null -%}
    $versions = $this->get('session')->get('{{ namespace_prefix }}\{{ bundle_name }}\{{ builder.BaseGeneratorName }}Edit\Versions', array());
    
    /* TODO: Propel has no locking mechanism so we'll implement a simple check */
    if ($object->getCurrentVersion !== $versions[$pk]) {
        throw new PropelException('Cannot write to outdated object version.');
    }
{%- endif %}
{% endblock %}

{% block lockException %}PropelException{% endblock %}
Add message to propel exception
Add message to propel exception