Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Soon/DataSync/docs/01_Getting_Started/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/app/code/Soon/DataSync/docs/01_Getting_Started/03_Examples.md
# Examples

## A basic export

Parse the data to CSV and put it a file located in magento_root/var/soon_datasync/data.csv.

```php
$this
    ->to('local')
    ->treatWith(function () {
        return ['first' => 'John', 'last' => 'Doe'];
    })
    ->go();
```

## Archiving to a specific file or disable archiving

* If the `archive()` method is not called, data is archived in `magento_root/var/soon_datasync/_archive/[import | export]`
* Same behavior if the `archive()` method is called without arguments.
* Use `archive(false)` to avoid archiving.

```php
$this
    ->to('local')
    ->archive('/var/www/html/magento/archive/my-archive.csv')
    ->treatWith(function () {
        return $this->exportData;
    })
    ->go();
```

## Export to XML

```php
$this
    ->dataOfType('xml')
    ->to('local')
    ->treatWith(function () {
        return ['first' => 'John', 'last' => 'Doe'];
    })
    ->go();
```

## Export to a custom location

Parse the data to CSV and put it a file located in magento_root/custom/dir/my-data.csv.

```php
$this
    // "~" means "Magento root dir". If avoided, absolute path is used.
    ->to('local', ['filepath' => '~/custom/dir/my-data.csv'])
    ->treatWith(function () {
        return $this->exportData;
    })
    ->go();
```

## Export to (S)FTP

Parse the data to CSV and put it a file located in the root dir of the (S)FTP.

```php
$this
    // Use 'sftp' for sftp!
    ->to('ftp', ['host' => 'x.x.x.x', 'user' => 'username', 'password' => 'pw'])
    ->treatWith(function () {
        return $this->exportData;
    })
    ->go();
```

## Basic import (with the ability to delete the source file once imported)

Fetch the 'magento_root/var/soon_datasync/data.csv' and return its content parsed as an array to the "treatWith" closure.

```php
$this
    // Use 'fromOnce' to delete the source file when the import is finished
    ->from('local')
    ->treatWith(function ($data) {
        var_dump($data);
    })
    ->go();
```

## A batch import to import several items (or filter by `*` wildcard)

Fetch all files matching the "glob" rule and process them one by one.

```php
$this
    ->glob('~/var/soon_datasync/d*ta.xml')
    ->dataOfType('xml')
    ->from('local')
    ->treatWith(function ($data) {
        var_dump($data);
    })
    ->go();
```

## Read the content of a file

Just reads the content of the LICENCE.txt file of the Magento installation.

```php
$this->from('local', ['filepath' => '~/LICENSE.txt']);
var_dump($this->which('transferType')->pull());
```

Spamworldpro Mini