PHP code example of bedita / import-tools

1. Go to this page and download the library: Download bedita/import-tools 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/ */

    

bedita / import-tools example snippets


'Datasources' => [
    // the target database
    'default' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',
        'host' => '***********',
        'port' => '***********',
        'username' => '***********',
        'password' => '***********',
        'database' => '***********',
        // ...
    ],
    // the remote database you want to you as source
    'import' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',
        'host' => '***********',
        'port' => '***********',
        'username' => '***********',
        'password' => '***********',
        'database' => '***********',
        // ...
    ],
],

'Translators' => [
    'deepl' => [
        'name' => 'DeepL',
        'class' => '\BEdita\I18n\Deepl\Core\Translator',
        'options' => [
            'auth_key' => '************',
        ],
    ],
]

use BEdita\ImportTools\Utility\CsvTrait;

class MyImporter
{
    use CsvTrait;

    public function import(string $filename): void
    {
        foreach ($this->readCsv($filename) as $obj) {
            // process $obj
        }
    }
}

use BEdita\ImportTools\Utility\FileTrait;

class MyImporter
{
    use FileTrait;

    public function read(string $file): void
    {
        [$fh, $close] = $this->readFileStream($path);

        try {
            flock($fh, LOCK_SH);
            // do your stuff
        } finally {
            $close();
        }
    }
}

use BEdita\ImportTools\Utility\TreeTrait;

class MyImporter
{
    use TreeTrait;

    public function import(string $filename, string $destination): void
    {
        foreach ($this->readCsv($filename) as $obj) {
            $this->setParent($obj, $destination);
        }
    }
}

use BEdita\ImportTools\Utility\Import;

class MyImporter
{
    public function import(string $filename, string $type, ?string $parent, ?bool $dryrun): void
    {
        $import = new Import($filename, $type, $parent, $dryrun);
        $import->saveObjects();
    }
}