Skip to content

Commit

Permalink
Over-ride monitor page within the extension
Browse files Browse the repository at this point in the history
This gives us a usable monitoring page for imports, without having to plan
out a solution that covers all potential use cases.

It should be a quick way to get this functionality operational
  • Loading branch information
eileenmcnaughton committed Nov 24, 2022
1 parent ae17034 commit f748a01
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
28 changes: 27 additions & 1 deletion ext/civiimport/civiimport.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Civi\API\Exception\UnauthorizedException;
use Civi\Api4\Mapping;
use Civi\Api4\UserJob;
use Civi\BAO\Import;
Expand Down Expand Up @@ -157,11 +158,36 @@ function _civiimport_civicrm_get_import_tables(): array {
* @param string $templateFile
*
* @noinspection PhpUnusedParameterInspection
* @throws \CRM_Core_Exception
*/
function civiimport_civicrm_alterTemplateFile($formName, $form, $type, &$templateFile) {
function civiimport_civicrm_alterTemplateFile($formName, $form, $type, &$templateFile): void {
if ($formName === 'CRM_Contribute_Import_Form_MapField') {
$templateFile = 'CRM/Import/MapField.tpl';
}
if ($formName === 'CRM_Queue_Page_Monitor') {
$jobName = CRM_Utils_Request::retrieveValue('name', 'String');
if (strpos($jobName, 'user_job_') === 0) {
try {
$userJobID = (int) str_replace('user_job_', '', $jobName);
$jobType = UserJob::get()->addWhere('id', '=', $userJobID)
->execute()->first()['job_type'];
foreach (CRM_Core_BAO_UserJob::getTypes() as $userJobType) {
if ($userJobType['id'] === $jobType
&& is_subclass_of($userJobType['class'], 'CRM_Import_Parser')
) {

$templateFile = 'CRM/Import/Monitor.tpl';
Civi::resources()
->addVars('civiimport', ['url' => CRM_Utils_System::url('civicrm/import/contact/summary', ['reset' => 1, 'user_job_id' => $userJobID])]);
break;
}
}
}
catch (UnauthorizedException $e) {
// We will not do anything here if not permissioned - leave it for the core page.
}
}
}
}

/**
Expand Down
15 changes: 15 additions & 0 deletions ext/civiimport/templates/CRM/Import/Monitor.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div id='crm-import-progress'></div>
{literal}
<script>
var target = '#crm-import-progress';
var url = CRM.vars.civiimport.url;
// Load the snippet into the container
CRM.loadPage(url, {
target: target,
block: false
})
window.setInterval(function() {
CRM.$(target).crmSnippet('refresh');
}, 1000);
</script>
{/literal}

0 comments on commit f748a01

Please sign in to comment.