PHP code example of phpcr / phpcr-migrations-bundle

1. Go to this page and download the library: Download phpcr/phpcr-migrations-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpcr / phpcr-migrations-bundle example snippets



// phpcr-migrations/Version201501011200.php

use PHPCR\SessionInterface;
use PHPCR\Migrations\VersionInterface;

class Version201501011200 implements VersionInterface
{
    public function up(SessionInterface $session): void
    {
        $session->getRootNode()->addNode('hello');
    }

    public function down(SessionInterface $session): void
    {
        $session->getRootNode()->getNode('hello')->remove();
    }
}


// app/phpcr-migrations/Version201501011212.php

use PHPCR\SessionInterface;
use PHPCR\Migrations\VersionInterface;

class Version201501011212 implements VersionInterface
{
    public function up(SessionInterface $session): void
    {
        $session->getNode('/hello')->addNode('world');
    }

    public function down(SessionInterface $session): void
    {
        $session->getNode('/hello')->getNode('world')->remove();
    }
}
`bash
$ php app/console phpcr:migrations:status
+--+---------------+------------------+----------+----------------------------------------------+
|  | Version       | Date             | Migrated | Path                                         |
+--+---------------+------------------+----------+----------------------------------------------+
|  | 201501011200 | 2015-01-01 12:00 | NO       | app/phpcr-migrations/Version201501011200.php |
|  | 201501011212 | 2015-01-01 12:12 | NO       | app/phpcr-migrations/Version201501011212.php |
+--+---------------+------------------+----------+----------------------------------------------+
No migrations have been executed