Download the PHP package taylornetwork/backup-importer without Composer
On this page you can find all versions of the php package taylornetwork/backup-importer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package backup-importer
Backup Importer
This package will allow you to import data to your database from a backup database that is not identical.
This is useful if you re-write an application and the database structure changes.
Install
Using Composer
Publish Config
Add Backup Database Config
By default this will use your mysql
database connection with the DB_BACKUP_DATABASE
value from your .env
file or backup
as the database name
Add connection details to config/backup-importer.php
Usage
Run your importers
Create an Importer
Would generate an importer App\Backup\Importers\CustomerImporter.php
by default.
Simple Importer
By default the importer assumes the following
- There is a model to import to
- The model being imported is
App\Customer
(see Advanced Config to change) - The backup table name is
customers
- The backup table fields are all the same as the model's fields
Advanced Importers
You can override the above assumptions on an importer by importer basis
Override Model
Add a protected $model
variable in your importer
Override the Backup Table Name
Add a protected $backupTableName
variable in your importer
Ignore Model (For a Pivot Table)
If you don't have a model for this importer set a protected $ignoreModel
to true
Override Columns From Backup Table
You can override the columns that are taken from the backup table, or rename them.
Add a public getColumnMap()
function that returns the array of columns to get.
Example
Customizing the import()
function
The import()
function by default will return $this->simpleImport()
which is fine for simple tables with no relations, however you will likely want to customize the import logic.
Notes
- Access the model by
$this->getModel()
- Access the database query data by
$this->items()
- Access the fluent builder for more complex queries by
$this->builder()
- Access the fluent builder AFTER the select call by
$this->select()
- Whenever you import a row you should call
$this->increment()
to add to the total of rows imported - If you use
$this->increment()
your return statement should be$this->getImportTotal()
Example
Let's say you have an application that has customers and services. Each customer can have many services with properties.
You have the following models which you store in app/
App\Customer
App\Service
App\CustomerService
For the customer and service models, you used the simple import method.
All versions of backup-importer with dependencies
illuminate/database Version 5.*.*
illuminate/console Version 5.*.*
php Version >=7.1.0