Editing a published article: how to avoid losing another edit

Two tabs used by one author can lose an edit. On MySQL 8.4/InnoDB, separate working and public revisions, check the original token and protect history with triggers.

Separate layers of text: a working edit, preserved history and the version readers see.
Separate layers of text: a working edit, preserved history and the version readers see.

A published article remains a working text. After publication, its author may notice an inaccuracy, rewrite an explanation or add an example. While those changes are being prepared, readers should see a coherent public version. If the same article is open in two tabs, the second save should not silently erase the first one.

The Revision module adds its own temporary MySQL 8.4/InnoDB teaching schema and command to the same Kernel. Its draft/public pointers concern the synthetic record in this exercise, rather than the existing notes catalogue. The two-tab test scenario remains a sequence of two snapshots on one runtime connection, rather than simultaneous load from two processes. Schema preparation uses a separate native PDO migrator connection.

This conflict does not require a large editorial team. One author, a morning tab with an unsaved paragraph and another tab where the title has already been corrected are enough. Both versions may contain useful work. The order in which someone presses Save does not, by itself, determine which text is correct.

“Article: how an author's journal becomes a product” discussed editorial packages and publication scheduling. Here we will examine a separate question: how to distinguish the working draft, revision history and public text. We extend the same Symfony 8.1 project with a MySQL 8.4/InnoDB exercise that explicitly rejects a stale edit.

One article, several different numbers

An article will have a stable id. Each successful save will create a new text revision. A separate article record will hold pointers to its working and published revisions, plus version, a numeric state token.

These numbers are not interchangeable. The revision number answers “which exact text?”, while version answers “has the state changed since I read it?”. Publishing moves the public pointer and increases the token, but does not rewrite the text or create another copy. After publication, the state version can therefore be 3 while both pointers are 2.

Moment State token Working revision Public revision
Both tabs read the article 1 1 1
Tab A saves new text 2 2 1
Tab B submits its old token 2 2 1
The author explicitly publishes revision 2 3 2 2

This is the lab's expected sequence, not a transcript of a completed run. We deliberately use one token for saving and publishing: any state change makes an old command stale. The cost of this simple policy is an additional conflict when another tab has only published the draft.

Preserve the state that editing started from

A database transaction should not remain open while a person reads and edits text. The Doctrine documentation on optimistic locking describes this distinction between a short transaction and a user's work across multiple requests. Our example implements the check through PDO, without an ORM.

The client must return the token received with the original text. If the server reads the current version just before saving and substitutes it for the old one, the check loses its purpose: stale text receives permission from a newer state. A hidden form field or command parameter carries the expected version; the server compares it with the database.

The token does not establish permission to edit. Authorization and HTTP request protection have their own rules. This console lab examines state changes, so it does not claim to provide a complete administration form.

The next step in the shared project

Continue the same Symfony project, article_demo, built from the official skeleton. Run commands from its root and preserve earlier routes, services and data. Add only the required public dependencies. Requirements are PHP 8.4+, Composer 2, MySQL 8.4 and the PDO MySQL driver. Reuse the previously introduced shared App\Infrastructure\MysqlLab and guarded fixtures/mysql_labs/run.sh wrapper for the disposable teaching server; do not create another application. Save the files below in the existing project. LabDatabase::createFixture() prepares an isolated temporary schema starting with one published revision, and the command and tests explicitly close the fixture afterward. This does not copy data from an old SQLite database.

composer require symfony/console:"8.1.*"
composer require --dev symfony/test-pack
mkdir -p src/Revision src/Command tests/Revision

A history that appends new records

The file src/Revision/LabDatabase.php explicitly prepares two InnoDB tables and the initial text through the migrator. It first creates articles, then article_revisions with its foreign key to the article, and only then uses ALTER TABLE to add the reverse composite pointer foreign keys. This creates the cyclic relationships in a valid order and connects each pointer to a revision belonging to that same article. The schema includes CHECK constraints, uses utf8mb4 with utf8mb4_0900_bin collation, and stores both title and body as LONGTEXT.

<?php

declare(strict_types=1);

namespace App\Revision;

use App\Infrastructure\MysqlLab;
use PDO;

final class LabDatabase
{
    public static function create(): PDO
    {
        return self::createFixture()->runtime();
    }

    public static function createFixture(): MysqlLab
    {
        $fixture = MysqlLab::create('revision');
        try {
            $db = $fixture->migrator();
            $db->exec(<<<'SQL'
                CREATE TABLE articles (
                    id BIGINT SIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
                    version BIGINT SIGNED NOT NULL CHECK (version >= 1),
                    draft_revision BIGINT SIGNED NULL,
                    published_revision BIGINT SIGNED NULL
                ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin
                SQL);
            $db->exec(<<<'SQL'
                CREATE TABLE article_revisions (
                    article_id BIGINT SIGNED NOT NULL,
                    revision BIGINT SIGNED NOT NULL CHECK (revision >= 1),
                    title LONGTEXT NOT NULL,
                    body LONGTEXT NOT NULL,
                    PRIMARY KEY (article_id, revision),
                    FOREIGN KEY (article_id) REFERENCES articles(id)
                ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin
                SQL);
            $db->exec(<<<'SQL'
                ALTER TABLE articles
                    ADD FOREIGN KEY (id, draft_revision) REFERENCES article_revisions(article_id, revision),
                    ADD FOREIGN KEY (id, published_revision) REFERENCES article_revisions(article_id, revision)
                SQL);
            $db->exec(<<<'SQL'
                CREATE TRIGGER revision_no_reinsert BEFORE INSERT ON article_revisions
                FOR EACH ROW
                BEGIN
                    IF EXISTS (
                        SELECT 1 FROM article_revisions
                        WHERE article_id = NEW.article_id AND revision = NEW.revision
                    ) THEN
                        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'append_only_revision';
                    END IF;
                END
                SQL);
            $db->exec(<<<'SQL'
                CREATE TRIGGER revision_no_update BEFORE UPDATE ON article_revisions
                FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'append_only_revision'
                SQL);
            $db->exec(<<<'SQL'
                CREATE TRIGGER revision_no_delete BEFORE DELETE ON article_revisions
                FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'append_only_revision'
                SQL);

            $db->beginTransaction();
            try {
                $db->exec('INSERT INTO articles (id, version) VALUES (1, 1)');
                $seed = $db->prepare('INSERT INTO article_revisions VALUES (?, ?, ?, ?)');
                $seed->execute([1, 1, 'Original title', 'Original body']);
                $db->exec('UPDATE articles SET draft_revision = 1, published_revision = 1 WHERE id = 1');
                $db->commit();
            } catch (\Throwable $error) {
                if ($db->inTransaction()) {
                    $db->rollBack();
                }
                throw $error;
            }
            return $fixture;
        } catch (\Throwable $error) {
            $fixture->close();
            throw $error;
        }
    }
}

A separate migrator executes DDL before the seed transaction. MySQL has statements that cause implicit commits, so this sequence is not an atomic upgrade of the entire schema. During seeding, the pointers are temporarily empty: insert the article, insert its revision, then connect them — these DML operations complete in one transaction. The editor receives a runtime connection without CREATE, ALTER or DROP privileges and reads an already prepared, published article; its initial editorial creation workflow is outside this example.

MySQL triggers reject history UPDATE and DELETE operations using SIGNAL with SQLSTATE '45000' and the message append_only_revision. A separate BEFORE INSERT checks for an existing article_id, revision pair and rejects reinsertion in the same way.

The insert guard also stops native MySQL REPLACE INTO for an existing pair: the command must not replace historical text. The test checks the append_only_revision message and verifies that the complete state and history remain unchanged after rejection. No SQLite trigger switches are involved.

The history primary key is the composite article_id, revision pair. The next revision number is calculated from the working pointer after the article's conditional update succeeds; it is not a separate automatic history counter. The key provides uniqueness, foreign keys enforce valid references, and triggers prohibit rewriting stored revisions.

This immutability applies to data operations under this schema. A database owner can change the schema or remove a trigger, so this is neither cryptographic evidence nor protection against an administrator. Revision authors, change timestamps and retention rules are also absent: they belong in a complete audit trail but do not determine the conflict mechanism.

Save the explicit error type in src/Revision/RevisionConflict.php.

<?php

declare(strict_types=1);

namespace App\Revision;

final class RevisionConflict extends \RuntimeException
{
}

A conditional update inside a short transaction

The file src/Revision/ArticleEditor.php contains state reads, history and two commands. In saveDraft, the first SQL operation changes the token only for a row with the expected version. This is compare-and-swap: comparison and mutation are part of one UPDATE, rather than independent “check” and “write” steps.

<?php

declare(strict_types=1);

namespace App\Revision;

use PDO;

final class ArticleEditor
{
    public function __construct(private readonly PDO $db)
    {
    }

    public function snapshot(int $id): array
    {
        $query = $this->db->prepare(<<<'SQL'
            SELECT a.id, a.version, a.draft_revision, a.published_revision,
                   d.title AS draft_title, d.body AS draft_body,
                   p.title AS public_title, p.body AS public_body
            FROM articles a
            JOIN article_revisions d
              ON d.article_id = a.id AND d.revision = a.draft_revision
            JOIN article_revisions p
              ON p.article_id = a.id AND p.revision = a.published_revision
            WHERE a.id = ?
            SQL);
        $query->execute([$id]);
        $row = $query->fetch();

        if ($row === false) {
            throw new \OutOfBoundsException('Seeded article not found.');
        }

        foreach (['id', 'version', 'draft_revision', 'published_revision'] as $key) {
            $row[$key] = (int) $row[$key];
        }

        return $row;
    }

    public function history(int $id): array
    {
        $query = $this->db->prepare(
            'SELECT revision, title, body FROM article_revisions WHERE article_id = ? ORDER BY revision'
        );
        $query->execute([$id]);
        $rows = $query->fetchAll();

        foreach ($rows as &$row) {
            $row['revision'] = (int) $row['revision'];
        }

        unset($row);

        return $rows;
    }

    public function saveDraft(int $id, int $expectedVersion, string $title, string $body): int
    {
        $title = trim($title);

        if ($expectedVersion < 1 || $title === '') {
            throw new \InvalidArgumentException('Positive version and nonblank title required.');
        }

        return $this->transaction(function () use ($id, $expectedVersion, $title, $body): int {
            $claim = $this->db->prepare(
                'UPDATE articles SET version = version + 1 WHERE id = ? AND version = ?'
            );
            $claim->execute([$id, $expectedVersion]);

            if ($claim->rowCount() !== 1) {
                throw new RevisionConflict('Article missing or changed; reload before saving.');
            }

            $current = $this->db->prepare('SELECT draft_revision FROM articles WHERE id = ?');
            $current->execute([$id]);
            $nextRevision = (int) $current->fetchColumn() + 1;

            $insert = $this->db->prepare(
                'INSERT INTO article_revisions (article_id, revision, title, body) VALUES (?, ?, ?, ?)'
            );
            $insert->execute([$id, $nextRevision, $title, $body]);

            $move = $this->db->prepare('UPDATE articles SET draft_revision = ? WHERE id = ?');
            $move->execute([$nextRevision, $id]);

            return $expectedVersion + 1;
        });
    }

    public function publish(int $id, int $expectedVersion, int $wantedRevision): int
    {
        if ($expectedVersion < 1 || $wantedRevision < 1) {
            throw new \InvalidArgumentException('Positive version and revision required.');
        }

        return $this->transaction(function () use ($id, $expectedVersion, $wantedRevision): int {
            $publish = $this->db->prepare(<<<'SQL'
                UPDATE articles
                SET version = version + 1, published_revision = ?
                WHERE id = ? AND version = ? AND draft_revision = ?
                SQL);
            $publish->execute([$wantedRevision, $id, $expectedVersion, $wantedRevision]);

            if ($publish->rowCount() !== 1) {
                throw new RevisionConflict('Article or selected draft changed; review before publishing.');
            }

            return $expectedVersion + 1;
        });
    }

    private function transaction(callable $operation): int
    {
        if ($this->db->inTransaction()) {
            throw new \LogicException('ArticleEditor must own its transaction.');
        }

        $this->db->beginTransaction();

        try {
            $version = $operation();
            $this->db->commit();

            return $version;
        } catch (\Throwable $error) {
            if ($this->db->inTransaction()) {
                $this->db->rollBack();
            }

            throw $error;
        }
    }
}

For UPDATE, PDOStatement::rowCount() reports affected rows. Every match here necessarily increments the version. One row allows the operation to continue; zero means the article is missing or the command is stale. The example deliberately combines those cases into one rejection, rather than claiming that any zero proves another editor was involved.

After a successful comparison, the code inserts a revision and moves the working pointer. This method leaves the public pointer unchanged. If inserting the text or completing the transaction throws, the code rolls back its own active transaction. The PDO transaction rules apply to the whole operation: a new number must not remain without its new text.

The class refuses to run inside someone else's transaction. This explicit contract prevents it from committing or rolling back changes owned by its caller. Values are passed through PDO parameters, while title validation uses ordinary PHP trim. That is not complete Unicode editorial validation.

Publish the exact text that was reviewed

The publish method has two conditions: the token must match, and the selected revision must match the current draft. Suppose the author reviewed revision 2, but another tab has already created 3. “Publish the reviewed revision 2” must stop. Replacing that request with “publish the latest” could expose text that the author has not yet checked.

This policy permits publishing only the current draft. To restore old text, a fuller system could create a new working revision from it and follow the normal review process. The lab does not introduce a hidden rollback mode. Repeating a command with its old token also conflicts; idempotent handling of a network request with an unknown outcome is not implemented here.

The console scenario in src/Command/RevisionConflictDemoCommand.php obtains two snapshots before the first save. They represent two tabs even when one person operates both. Its AsCommand registration follows the Symfony Console documentation.

<?php

declare(strict_types=1);

namespace App\Command;

use App\Revision\ArticleEditor;
use App\Revision\LabDatabase;
use App\Revision\RevisionConflict;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'app:revision-conflict-demo', description: 'Demonstrate a stale editorial save.')]
final class RevisionConflictDemoCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $fixture = LabDatabase::createFixture();
        try {
            $editor = new ArticleEditor($fixture->runtime());
            $tabA = $editor->snapshot(1);
            $tabB = $editor->snapshot(1);

            $editor->saveDraft(1, $tabA['version'], 'First edit', 'Updated body');
            $afterSave = $editor->snapshot(1);
            $conflict = false;

            try {
                $editor->saveDraft(1, $tabB['version'], 'Second edit', 'Stale body');
            } catch (RevisionConflict) {
                $conflict = true;
            }

            $afterConflict = $editor->snapshot(1);

            $editor->publish(1, $afterConflict['version'], $afterConflict['draft_revision']);
            $afterPublish = $editor->snapshot(1);
            $history = $editor->history(1);

            $output->writeln(json_encode([
                'tab_a' => $tabA,
                'tab_b' => $tabB,
                'after_save' => $afterSave,
                'conflict_reported' => $conflict,
                'after_conflict' => $afterConflict,
                'after_publish' => $afterPublish,
                'history' => $history,
            ], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR), OutputInterface::OUTPUT_RAW);

            return $conflict
                && $afterSave === $afterConflict
                && $afterSave['published_revision'] === 1
                && $afterPublish['published_revision'] === 2
                && count($history) === 2
                ? Command::SUCCESS
                : Command::FAILURE;
        } finally {
            $fixture->close();
        }
    }
}

Merge these definitions under the existing services key in config/services.yaml. Preserve earlier registrations, _defaults and imports; keep the rest of the file. DTOs and static factories do not need broad App\ service scanning.

services:
    App\Command\RevisionConflictDemoCommand: ~

Check the consequences of rejection too

Checking that the second call throws an exception is insufficient. Compare the entire state and history before and after it. Otherwise, an implementation could report a conflict after it has already erased text or moved the public pointer.

The file tests/Revision/ArticleEditorTest.php checks preservation of accepted text after a stale edit, explicit publication and rejection of the wrong revision. An injected trigger using SIGNAL SQLSTATE '45000' checks rollback of the version increment after insertion fails and allows a subsequent retry. Direct UPDATE, DELETE and REPLACE INTO operations must not change history. Further checks cover rejection of caller-owned transactions, a blank title, and foreign-key error 1452 for a missing revision without finishing the caller's transaction. Each test receives a fresh temporary MySQL schema; only the separate migrator installs and removes the injected trigger, while the editor and data assertions use the runtime connection.

<?php

declare(strict_types=1);

namespace App\Tests\Revision;

use App\Infrastructure\MysqlLab;
use App\Revision\ArticleEditor;
use App\Revision\LabDatabase;
use App\Revision\RevisionConflict;
use PDO;
use PDOException;
use PHPUnit\Framework\TestCase;

final class ArticleEditorTest extends TestCase
{
    private MysqlLab $fixture;
    private PDO $db;
    private ArticleEditor $editor;

    protected function setUp(): void
    {
        $this->fixture = LabDatabase::createFixture();
        $this->db = $this->fixture->runtime();
        $this->editor = new ArticleEditor($this->db);
    }

    protected function tearDown(): void
    {
        $this->fixture->close();
    }

    public function testStaleSavePreservesWinnerAndPublishedRevision(): void
    {
        $tabA = $this->editor->snapshot(1);
        $tabB = $this->editor->snapshot(1);
        self::assertSame(2, $this->editor->saveDraft(1, $tabA['version'], 'Winner', 'Draft body'));
        $winner = $this->editor->snapshot(1);
        $history = $this->editor->history(1);

        $this->assertConflict(fn () => $this->editor->saveDraft(1, $tabB['version'], 'Loser', 'Old body'));

        self::assertSame($winner, $this->editor->snapshot(1));
        self::assertSame($history, $this->editor->history(1));
        self::assertSame('Winner', $winner['draft_title']);
        self::assertSame('Original title', $winner['public_title']);
        self::assertSame(2, $winner['draft_revision']);
        self::assertSame(1, $winner['published_revision']);
        self::assertCount(2, $history);
    }

    public function testExplicitPublishMovesOnlyThePublicPointerAndVersion(): void
    {
        $this->editor->saveDraft(1, 1, 'Reviewed', 'Ready body');
        $history = $this->editor->history(1);

        self::assertSame(3, $this->editor->publish(1, 2, 2));

        $state = $this->editor->snapshot(1);
        self::assertSame(3, $state['version']);
        self::assertSame(2, $state['draft_revision']);
        self::assertSame(2, $state['published_revision']);
        self::assertSame('Reviewed', $state['public_title']);
        self::assertSame($history, $this->editor->history(1));
    }

    public function testStaleOrWrongDraftCannotBePublished(): void
    {
        $this->editor->saveDraft(1, 1, 'Reviewed draft', 'Second');
        $this->editor->saveDraft(1, 2, 'Unreviewed draft', 'Third');
        $before = $this->editor->snapshot(1);
        $history = $this->editor->history(1);

        $this->assertConflict(fn () => $this->editor->publish(1, 2, 2));
        $this->assertConflict(fn () => $this->editor->publish(1, 3, 2));

        self::assertSame($before, $this->editor->snapshot(1));
        self::assertSame($history, $this->editor->history(1));
        self::assertSame(1, $before['published_revision']);
    }

    public function testInsertFailureRollsBackVersionAndAllowsRetry(): void
    {
        $before = $this->editor->snapshot(1);
        $history = $this->editor->history(1);
        $this->fixture->migrator()->exec(<<<'SQL'
            CREATE TRIGGER inject_insert_failure BEFORE INSERT ON article_revisions FOR EACH ROW
            BEGIN
                IF NEW.revision = 2 THEN
                    SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'injected_insert_failure';
                END IF;
            END
            SQL);

        try {
            $this->editor->saveDraft(1, 1, 'Attempt', 'Body');
            self::fail('The injected database failure was not raised.');
        } catch (PDOException $error) {
            self::assertStringContainsString('injected_insert_failure', $error->getMessage());
        }

        self::assertFalse($this->db->inTransaction());
        self::assertSame($before, $this->editor->snapshot(1));
        self::assertSame($history, $this->editor->history(1));
        $this->fixture->migrator()->exec('DROP TRIGGER inject_insert_failure');
        self::assertSame(2, $this->editor->saveDraft(1, 1, 'Retry', 'Body'));
        self::assertCount(2, $this->editor->history(1));
    }

    public function testStoredRevisionCannotBeUpdated(): void
    {
        $history = $this->editor->history(1);

        try {
            $this->db->exec("UPDATE article_revisions SET title = 'Replaced' WHERE article_id = 1");
            self::fail('Updating revision history must fail.');
        } catch (PDOException $error) {
            self::assertStringContainsString('append_only_revision', $error->getMessage());
        }
        self::assertSame($history, $this->editor->history(1));
    }

    public function testStoredRevisionCannotBeDeleted(): void
    {
        $history = $this->editor->history(1);

        try {
            $this->db->exec('DELETE FROM article_revisions WHERE article_id = 1');
            self::fail('Deleting revision history must fail.');
        } catch (PDOException $error) {
            self::assertStringContainsString('append_only_revision', $error->getMessage());
        }
        self::assertSame($history, $this->editor->history(1));
    }

    public function testStoredRevisionCannotBeReplacedWithRecursiveTriggersDisabled(): void
    {
        // Historical method name retained: MySQL has no SQLite recursive_triggers
        // switch. Its native REPLACE must still hit the append-only insert guard.
        $before = $this->editor->snapshot(1);
        $history = $this->editor->history(1);

        try {
            $replace = $this->db->prepare(
                'REPLACE INTO article_revisions (article_id, revision, title, body) VALUES (?, ?, ?, ?)'
            );
            $replace->execute([1, 1, 'Replacement title', 'Replacement body']);
            self::fail('Replacing an existing revision must fail.');
        } catch (PDOException $error) {
            self::assertStringContainsString('append_only_revision', $error->getMessage());
        }
        self::assertSame($before, $this->editor->snapshot(1));
        self::assertSame($history, $this->editor->history(1));
    }

    public function testCallerTransactionIsNeitherCommittedNorRolledBack(): void
    {
        $before = $this->editor->snapshot(1);
        $this->db->beginTransaction();

        try {
            $this->editor->saveDraft(1, 1, 'Nested', 'Body');
            self::fail('A caller-owned transaction must be rejected.');
        } catch (\LogicException $error) {
            self::assertSame('ArticleEditor must own its transaction.', $error->getMessage());
            self::assertTrue($this->db->inTransaction());
            self::assertSame($before, $this->editor->snapshot(1));
        } finally {
            if ($this->db->inTransaction()) {
                $this->db->rollBack();
            }
        }
    }

    public function testBlankTitleDoesNotChangeState(): void
    {
        $before = $this->editor->snapshot(1);
        $history = $this->editor->history(1);

        try {
            $this->editor->saveDraft(1, 1, " \t\n ", 'Body');
            self::fail('A blank title must be rejected.');
        } catch (\InvalidArgumentException) {
            self::assertSame($before, $this->editor->snapshot(1));
            self::assertSame($history, $this->editor->history(1));
            self::assertFalse($this->db->inTransaction());
        }
    }

    public function testPointerForeignKeysRejectMissingRevisionWithoutRollingBackCaller(): void
    {
        $before = $this->editor->snapshot(1);
        $this->db->beginTransaction();
        try {
            try {
                $this->db->exec('UPDATE articles SET draft_revision = 999 WHERE id = 1');
                self::fail('Missing revision must violate the foreign key.');
            } catch (PDOException $error) {
                self::assertSame(1452, (int) $error->errorInfo[1]);
                self::assertTrue($this->db->inTransaction());
                self::assertSame($before, $this->editor->snapshot(1));
            }
        } finally {
            $this->db->rollBack();
        }
    }

    private function assertConflict(callable $operation): void
    {
        try {
            $operation();
            self::fail('A stale or mismatched command must conflict.');
        } catch (RevisionConflict) {
            self::assertFalse($this->db->inTransaction());
        }
    }
}

Run the container check, demonstration and PHPUnit, following the Symfony testing approach. For the demonstration and tests, use the guarded shared MySQL fixture wrapper shown below: it supplies the teaching server configuration, and MysqlLab creates and removes its own schema. Credentials are not inferred from a file path or an imaginary default connection.

php bin/console lint:container
bash fixtures/mysql_labs/run.sh php bin/console app:revision-conflict-demo
bash fixtures/mysql_labs/run.sh php vendor/bin/phpunit tests/Revision/ArticleEditorTest.php

A lock error, deadlock or other technical InnoDB failure is distinct from RevisionConflict; the different consequences of errors are described in the InnoDB documentation. The editor does not disguise every database exception as an editorial conflict: it rolls back its own still-active transaction and propagates the error. These checks establish state and history invariants in the scenarios shown, not parallel-load characteristics or production readiness of a complete editor.

What a person should see after a conflict

The interface should preserve the tab's unsaved text, show the current revision and let the author compare both with the original. A simple option is three separate views: “original”, “current” and “my edit”. After deliberately combining the changes, the author obtains a new token and saves the result again. Automatically resubmitting old text with a new token would bring back the same lost edit in another form.

For multiple languages, first decide the boundary of a revision: one translation or the whole article package. This example stores one text, so it does not establish atomic publication of all locales together. That boundary follows an editorial rule, not the name of the version field.

The useful result of this model is that each action can be explained. Saving adds working text. A conflict preserves the state already accepted. Publishing exposes one specific reviewed revision. Those distinctions belong in the future editor's buttons, messages and tests.

The shared MySQL fixture and its files are introduced in the transaction chapter. Run commands from the single article_demo root; do not create a separate Symfony application for each article.

Check the current example against an owned disposable MySQL schema:

  1. Editorial Stable content identity: Content ID, slug, revision and DB ID
  2. Editorial Draft, review, publication: a state model for one article
  3. Symfony Core Reimporting content: where updates are allowed and where to stop
  4. Editorial Correcting an article without broken links or silently rewriting history

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article