PHP code example of justinholtweb / craft-archive

1. Go to this page and download the library: Download justinholtweb/craft-archive 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/ */

    

justinholtweb / craft-archive example snippets


use justinholtweb\archive\services\CollectorRegistry;
use justinholtweb\archive\services\WriterRegistry;
use yii\base\Event;

// Teach Archive about your plugin's element type.
Event::on(CollectorRegistry::class, CollectorRegistry::EVENT_REGISTER_COLLECTORS,
    function($event) {
        $event->collectors[] = new MyElementCollector();
    });

// Add an output format — including a target-specific one, like WordPress WXR.
Event::on(WriterRegistry::class, WriterRegistry::EVENT_REGISTER_WRITERS,
    function($event) {
        $event->writers[] = new WxrWriter();
    });
sh
php craft archive/export
php craft archive/export --types=entries,assets --format=csv
php craft archive/export --sites=default,fr --sections=news --name=news-only
php craft archive/export --queue          # hand it to the queue instead

php craft archive/bundles                 # list them
php craft archive/bundles/prune           # apply the retention settings
php craft archive/bundles/delete 4
sh
composer install && vendor/bin/phpunit                  # unit
CRAFT_BASE_PATH=/path/to/project php tests/integration/export-roundtrip.php