Craft\ImportController::actionImport PHP Method

actionImport() public method

Start import task.
public actionImport ( )
    public function actionImport()
    {
        // Get import post
        $settings = craft()->request->getRequiredPost('import');
        // Get file
        $fileId = craft()->request->getParam('file');
        $file = craft()->assets->getFileById($fileId);
        // Get mapping fields
        $map = craft()->request->getParam('fields');
        $unique = craft()->request->getParam('unique');
        // Get rows/steps from file
        $rows = count(craft()->import->data($file->id));
        // Proceed when atleast one row
        if ($rows) {
            // Set more settings
            $settings = array_merge(array('user' => craft()->userSession->getUser()->id, 'file' => $file->id, 'rows' => $rows, 'map' => $map, 'unique' => $unique), $settings);
            // Create history
            $history = craft()->import_history->start($settings);
            // Add history to settings
            $settings['history'] = $history;
            // UNCOMMENT FOR DEBUGGING
            //craft()->import->debug($settings, $history, 1);
            // Create the import task
            $task = craft()->tasks->createTask('Import', Craft::t('Importing') . ' ' . $file->filename, $settings);
            // Notify user
            craft()->userSession->setNotice(Craft::t('Import process started.'));
            // Redirect to history
            $this->redirect(UrlHelper::getCpUrl('import/history', array('task' => $task->id)));
        } else {
            // Redirect to history
            $this->redirect(UrlHelper::getCpUrl('import/history'));
        }
    }