Skip to content
Snippets Groups Projects
Commit 8b5dc112 authored by Shane Bill's avatar Shane Bill
Browse files

advimport#5 Removing integration of core

parent 74546171
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,6 @@ Aims to fill the gap for the following type of needs:
* Tracks which row of data modified which CiviCRM entity (ex: helps to review that the import worked as expected).
* Supports large files (as long as your server allows uploading them, it has been tested with Excel files with an average of 50,000 rows).
* Can regularly run imports using a Scheduled Job, assuming a custom 'helper' that fetches data from a remote location (ex: from a third-party service) or a specific location on disk.
* The contact import and contribution import from "core" can be processed with advimport, to avoid any timeouts during the import. It also makes it possible to review errors and track the imported contact IDs.
* The contact import from core can have a column called "tags" (the name must be exact), with a list of either tag names or IDs (separated by ";"), in order to add multiple tags at once.
* The API3 Contribution/Participant import can match contacts based on their `external_identifier`.
......
......@@ -279,91 +279,7 @@ function advimport_civicrm_alterAPIPermissions($entity, $action, &$params, &$per
/**
* Implements hook_civicrm_buildForm().
*/
function advimport_civicrm_buildForm($formName, $form) {
// Core contact import
$supportedCoreMapField = [
'CRM_Contact_Import_Form_MapField' => 'CRM_Advimport_Advimport_CoreContact',
'CRM_Contribute_Import_Form_MapField' => 'CRM_Advimport_Advimport_CoreContribution',
];
$supportedCorePreview = [
'CRM_Contact_Import_Form_Preview' => 'CRM_Advimport_Advimport_CoreContact',
'CRM_Contribute_Import_Form_Preview' => 'CRM_Advimport_Advimport_CoreContribution',
];
// Core MapField Form: save the import settings
if (isset($supportedCoreMapField[$formName])) {
// Contact Import creates the table already, but Contribution does not
$importTableName = $form->get('importTableName');
$values = $form->exportValues();
// Check if we have already registered this import (from going previous/next)
if ($importTableName) {
$id = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_advimport WHERE table_name = %1', [
1 => [$importTableName, 'String'],
]);
}
if (!$id) {
if (!$importTableName) {
$file = $form->controller->exportValue('DataSource', 'uploadFile');
$separator = $form->controller->exportValue('DataSource', 'fieldSeparator');
if (!empty($file['name'])) {
$classname = $supportedCoreMapField[$formName];
$helper = new $classname();
list($headers, $data) = $helper->getDataFromFile($file['name'], $separator);
$x = new CRM_Advimport_Upload_Form_DataUpload();
$importTableName = $x->saveToDatabaseTable($headers, $data);
$form->set('importTableName', $importTableName);
}
}
if ($importTableName) {
$id = CRM_Advimport_BAO_Advimport::create([
'contact_id' => CRM_Core_Session::singleton()->get('userID'),
'classname' => $supportedCoreMapField[$formName],
'filename' => '',
'table_name' => $importTableName,
]);
}
}
$mapping = [
'mapper' => $values['mapper'],
'mapFields' => $form->get('fields'),
'disableUSPS' => $form->get('disableUSPS'),
'dedupe' => $form->get('dedupe'),
'onDuplicate' => $form->get('onDuplicate'),
'dateFormats' => $form->get('dateFormats'),
'contactType' => $form->get('contactType'),
'contactSubType' => $form->get('contactSubType'),
'primaryKeyName' => $form->get('primaryKeyName'),
];
// We might be updating the mapping from the UI (previous/next), so keep this separate from the create
CRM_Core_DAO::executeQuery('UPDATE civicrm_advimport SET mapping = %1 WHERE id = %2', [
1 => [json_encode($mapping), 'String'],
2 => [$id, 'Positive'],
]);
}
// Core Preview Form: add a button to continue with Advimport
elseif (isset($supportedCorePreview[$formName])) {
// Fetch the associated advimport entry
$importTableName = $form->get('importTableName');
$id = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_advimport WHERE table_name = %1', [
1 => [$importTableName, 'String'],
]);
// Add a button to continue with advimport
// (quick hack, there must be an easier way?)
$url = CRM_Utils_System::url('civicrm/advimport', 'reset=1&aid=' . $id);
Civi::resources()
->addMarkup('<a href="' . $url . '" class="crm-button button" id="crm-advimport-button">Import with Advimport</a>', 'form-top')
->addScript('CRM.$(function($) { $("#crm-advimport-button").appendTo(".crm-submit-buttons"); });');
}
}
function advimport_civicrm_buildForm($formName, $form) {}
/**
* Implements hook_civicrm_import().
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment