<commit_before><?php
namespace Atlas\Database;

class Write
{
    protected $_adapter;

    protected $_mapper;

    public function __construct($adapter, $mapper)
    {
        $this->_adapter = $adapter;
        $this->_mapper = $mapper;
    }

    /**
     * @param string $table
     * @param array $data
     * @param Atom_Model_Entity $entity
     * @param string $pkField
     */
    public function save($entity, $column = 'id')
    {
        if ($entity->getId() !== null) {
            $this->update($entity, $column);
        }

        $this->insert($entity);
    
        return $entity->getId();
    }

    public function insert($entity)
    {
        $insert = new Sql\Insert(
            $this->_mapper->getTable(),
            $this->_mapper->extract($entity)
        );

        $result = $this->execute($insert);

        $entity->setId($this->_adapter->lastInsertId());
        $entity->notify('create');

        return $entity->getId();
    }

    public function update($entity, $column)
    {
        $update = new Sql\Update(
            $this->_mapper->getTable(), 
            $this->_mapper->extract($entity),
            (new Sql\Where())->isEqual($column, $entity->getId())
        );

        $result = $this->execute($update);
        $entity->notify('change');<commit_msg>Fixed insert condition<commit_after><?php
namespace Atlas\Database;

class Write
{
    protected $_adapter;

    protected $_mapper;

    public function __construct($adapter, $mapper)
    {
        $this->_adapter = $adapter;
        $this->_mapper = $mapper;
    }

    /**
     * @param string $table
     * @param array $data
     * @param Atom_Model_Entity $entity
     * @param string $pkField
     */
    public function save($entity, $column = 'id')
    {
        if ($entity->getId() !== null) {
            $this->update($entity, $column);
        } else {
            $this->insert($entity);
        }
    
        return $entity->getId();
    }

    public function insert($entity)
    {
        $insert = new Sql\Insert(
            $this->_mapper->getTable(),
            $this->_mapper->extract($entity)
        );

        $result = $this->execute($insert);

        $entity->setId($this->_adapter->lastInsertId());
        $entity->notify('create');

        return $entity->getId();
    }

    public function update($entity, $column)
    {
        $update = new Sql\Update(
            $this->_mapper->getTable(), 
            $this->_mapper->extract($entity),
            (new Sql\Where())->isEqual($column, $entity->getId())
        );

        $result = $this->execute($update);
        $entity->notify('change');
{'fraction_non_alphanumeric': 0.1650889814464218, 'fraction_numerical': 0.0, 'mean_word_length': 2.054335260115607, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '638705', 'n_tokens_mistral': 771, 'n_tokens_neox': 757, 'n_words': 144}