{"id":21559626,"url":"https://github.com/elfuvo/yii2-import-wizard","last_synced_at":"2025-07-19T03:04:21.778Z","repository":{"id":56976615,"uuid":"287264965","full_name":"eLFuvo/yii2-import-wizard","owner":"eLFuvo","description":"Пошаговый импорт из Excel файлов с сопоставлением атрибутов модели","archived":false,"fork":false,"pushed_at":"2021-11-26T07:59:04.000Z","size":293,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-25T22:04:36.305Z","etag":null,"topics":["excel-import","inserting-data","wizard","yii2"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eLFuvo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-13T11:47:29.000Z","updated_at":"2022-06-07T13:31:26.000Z","dependencies_parsed_at":"2022-08-21T07:40:29.276Z","dependency_job_id":null,"html_url":"https://github.com/eLFuvo/yii2-import-wizard","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/eLFuvo/yii2-import-wizard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eLFuvo%2Fyii2-import-wizard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eLFuvo%2Fyii2-import-wizard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eLFuvo%2Fyii2-import-wizard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eLFuvo%2Fyii2-import-wizard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eLFuvo","download_url":"https://codeload.github.com/eLFuvo/yii2-import-wizard/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eLFuvo%2Fyii2-import-wizard/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265879062,"owners_count":23843062,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["excel-import","inserting-data","wizard","yii2"],"created_at":"2024-11-24T09:08:07.798Z","updated_at":"2025-07-19T03:04:21.553Z","avatar_url":"https://github.com/eLFuvo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://img.shields.io/github/v/release/elfuvo/yii2-import-wizard.svg)](https://packagist.org/packages/elfuvo/yii2-import-wizard) \n[![Build](https://img.shields.io/github/workflow/status/elfuvo/yii2-import-wizard/Build.svg)](https://github.com/elfuvo/yii2-import-wizard)\n[![License](https://img.shields.io/github/license/elfuvo/yii2-import-wizard.svg)](https://github.com/elfuvo/yii2-import-wizard/blob/master/LICENSE)\n[![Yii2](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](http://www.yiiframework.com/)\n\n##### Table of Contents\n[Requirements](#requirements)\u003cbr /\u003e\n[Installation](#installation)\u003cbr /\u003e\n[Configure](#configure)\n - [Module common configuration](#configure)\n - [I18n messages](#i18n)\n - [Actions](#actions)\n    + [Upload import file action](#upload-import-file-action)\n    + [Upload import file action with pre-defined attribute map](#upload-import-file-action-with-pre-defined-attribute-map)\n    + [Import setup action](#import-setup-action)\n    + [Current progress action](#current-progress-action)\n\n[Queue job](#queue-job)\u003cbr /\u003e\n[Import link button](#import-link-button)\u003cbr /\u003e\n[Additional notes](#additional-notes)\u003cbr /\u003e\n[Screenshots](#screenshots)\n\n## Requirements\n\n* PHP \u003e=7.1\n\n## Installation\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist elfuvo/yii2-import-wizard \"~0.2.0\"\n```\n\nor add\n\n```\n\"elfuvo/yii2-import-wizard\": \"~0.2.0\"\n```\n\nto the \"require\" section of your `composer.json` file.\n\n## Configure\n\nConfigure service for importing, Importing result keeper and available import adapters.\n\n```php\n// in common app config\n[\n'container'=\u003e[\n    'definitions' =\u003e [\n           \\elfuvo\\import\\services\\ImportServiceInterface::class =\u003e [\n                'class' =\u003e \\elfuvo\\import\\services\\ImportService::class,\n                'casters' =\u003e [\n                    // there is a custom value casters \n                    // \\elfuvo\\import\\services\\BracketValueCaster::class,\n                ]\n            ],\n            \\elfuvo\\import\\result\\ResultImportInterface::class =\u003e\n                \\elfuvo\\import\\result\\FileContinuesResultImport::class,\n            \\elfuvo\\import\\adapter\\AdapterFabricInterface::class =\u003e [\n                'class' =\u003e \\elfuvo\\import\\adapter\\AdapterFabricDefault::class,\n                'adapters' =\u003e [\n                    \\elfuvo\\import\\adapter\\AdapterImportExcel::class,\n                    \\elfuvo\\import\\adapter\\AdapterImportCsv::class,\n                ]\n            ],    \n        ],\n    ],\n];\n```\n\n## I18n\nAdd translations to i18n yii component:\n\n```php\n[\n    'components' =\u003e [\n        'i18n' =\u003e [\n                'class' =\u003e \\yii\\i18n\\I18N::class,\n                'translations' =\u003e [\n                    'import-wizard' =\u003e [\n                        'class' =\u003e \\yii\\i18n\\PhpMessageSource::class,\n                        'sourceLanguage' =\u003e 'en',\n                        'basePath' =\u003e '@vendor/elfuvo/yii2-import/src/messages',\n                    ],\n                ],\n        ]\n    ]\n];\n```\n## Actions\nAdd import steps actions to your controller\n```php\nclass DefaultController extend \\yii\\web\\Controller{\n    \n    public function actions()\n    {\n        return [\n            'upload-file-import' =\u003e [ // action with form for uploading import file\n                'class' =\u003e \\elfuvo\\import\\actions\\UploadFileAction::class,\n                ...\n            ],\n            'setup-import' =\u003e [ // action with import configuration form\n                'class' =\u003e \\elfuvo\\import\\actions\\SetupAction::class,\n                ...\n            ],\n            'progress' =\u003e [ // action for showing current import progress/statistic and errors after import is done\n                'class' =\u003e \\elfuvo\\import\\actions\\ProgressAction::class,\n            ],\n        ];\n    }\n}\n\n```\n\n### Upload import file action\n\n```php\n    public function actions()\n    {\n        return [\n            'upload-file-import' =\u003e [\n                'class' =\u003e \\elfuvo\\import\\actions\\UploadFileAction::class,\n                'model' =\u003e new Review(), // model instance for import\n                'nextAction' =\u003e 'setup-import', // next action name\n                'progressAction' =\u003e 'progress', // name of progress action\n            ],\n            ...\n        ];\n    }\n```\n\n### Upload import file action with pre-defined attribute map\nIf you are using attribute map, that you don't need configure setup action. Import starts after file uploaded. \n\n```php\n    public function actions()\n    {\n        return [\n            'upload-file-import-map' =\u003e [\n                'class' =\u003e UploadFileAction::class,\n                // model instance with pre-defined attribute values. It will be cloned in import service.\n                // can be callable function that returns model\n                'model' =\u003e new Review([\n                    'language' =\u003e 'ru',\n                    'hidden' =\u003e Review::HIDDEN_NO,\n                ]),\n                'startRowIndex' =\u003e 2,\n                // can be callable function that return array of MapAttribute models\n                // first argument for that function is first row from import file\n                'attributeMap' =\u003e [\n                    new MapAttribute([\n                        'column' =\u003e 'A',\n                        'attribute' =\u003e 'b24StationId',\n                        'castTo' =\u003e BracketValueCaster::class,\n                    ]),\n                    new MapAttribute([\n                        'column' =\u003e 'B',\n                        'attribute' =\u003e 'title',\n                        'castTo' =\u003e MapAttribute::TYPE_STRING,\n                        'identity' =\u003e 1,\n                    ]),\n                    new MapAttribute([\n                        'column' =\u003e 'C',\n                        'attribute' =\u003e 'author',\n                        'castTo' =\u003e MapAttribute::TYPE_STRING,\n                    ]),\n                    new MapAttribute([\n                        'column' =\u003e 'D',\n                        'attribute' =\u003e 'text',\n                        'castTo' =\u003e MapAttribute::TYPE_STRING,\n                    ]),\n                    new MapAttribute([\n                        'column' =\u003e 'E',\n                        'attribute' =\u003e 'rating',\n                        'castTo' =\u003e MapAttribute::TYPE_FLOAT,\n                    ]),\n                    new MapAttribute([\n                        'column' =\u003e 'F',\n                        'attribute' =\u003e 'publishAt',\n                        'castTo' =\u003e MapAttribute::TYPE_DATETIME,\n                    ]),\n                ],\n                'progressAction' =\u003e 'progress',\n            ],\n        ];\n   }\n```\n\n### Import setup action\n\n```php\n    public function actions()\n    {\n        return [\n        ...\n        'setup-import' =\u003e [\n                'class' =\u003e \\elfuvo\\import\\actions\\SetupAction::class,\n                // model instance with pre-defined attribute values. It will be cloned in import service.\n                /*'model' =\u003e new Review([ \n                      'hidden' =\u003e Review::HIDDEN_NO,\n                      'language' =\u003e Yii::$app-\u003elanguage,\n                      'createdBy' =\u003e Yii::$app-\u003euser-\u003egetId(),\n                ])*/\n                // can be callable function\n                'model' =\u003e function(){ \n                    $importModel = new Review([\n                        'hidden' =\u003e Review::HIDDEN_NO,\n                        'language' =\u003e Yii::$app-\u003elanguage,\n                        'createdBy' =\u003e Yii::$app-\u003euser-\u003egetId(),\n                    ]);\n                    // some behaviors do not work in console app (for queued import)\n                    // there we can disable them \n                    $importModel-\u003edetachBehavior('LanguageBehavior');\n                    $importModel-\u003edetachBehavior('CreatedByBehavior');\n                    \n                    return $importModel;\n                },                     \n                'scenario' =\u003e Review::SCENARIO_DEFAULT, // scenario of model validation when saving model from import\n                'previousAction' =\u003e 'upload-file-import', // previous action name\n                'excludeAttributes' =\u003e [ // exclude model attributes for building import map\n                    'id',\n                    'language',\n                    'createdBy',\n                    'createdAt',\n                    'updatedAt'\n                ]\n            ],\n        ];\n    )\n```\n\n### Current progress action\n```php\n    public function actions() {\n        return [\n            ...\n            'progress' =\u003e [\n                'class' =\u003e \\elfuvo\\import\\actions\\ProgressAction::class,\n                'model' =\u003e new Review(),\n            ],\n        ];\n    }\n```\n\n## Queue job\nIf queue component is not configured for Yii application then import will start immediately.\nOtherwise `ImportJob` will be added to the task queue.\n\nYii2 [queue](https://github.com/yiisoft/yii2-queue/blob/master/docs/guide/README.md).\n\n\n## Import link button\nAdd import link button into your module view:\n\n```php\n    \u003c?= Html::a(Yii::t('import-wizard', 'Import models from Excel file'), ['upload-file-import'], [\n         'class' =\u003e 'btn btn-primary'\n    ]) ?\u003e\n```\n\n## Additional notes\n\nModel validation rules used as detection for casting value from import.\nThis actual for setup import action.\nIt is necessary to carefully consider validation of the model, \nas bad validation may lead to incorrect data insertion \n(for example: a date from Excel cannot be inserted as a date in MySql) and errors when inserting data into the database.\n\n```php\n    /**\n     * @inheritdoc\n     */\n    public function rules()\n    {\n        return [\n                [['rating'], 'double', 'min' =\u003e 1, 'max' =\u003e 5], // will add float converter in import wizard\n                [['publishAt'], 'date', 'format' =\u003e 'yyyy-MM-dd HH:mm:ss'], // will add date converter in import wizard\n        ];\n    }\n\n```\n\nImportant! Import file must have column(s) with unique (identity) values for updating existing models.\n\n## Screenshots\n\n![Step 1](resources/upload-file.png \"step 1 - upload file for import\")\n![Step 2](resources/import-setup.png \"step 2 - setup import map\")\n![Step 3](resources/progress.png \"step 3 - wait until import done\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felfuvo%2Fyii2-import-wizard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felfuvo%2Fyii2-import-wizard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felfuvo%2Fyii2-import-wizard/lists"}