Unverified Commit 39e6208a authored by everykittysdaydream's avatar everykittysdaydream Committed by GitHub

Merge pull request #4 from 4ndygu/pipeline_new

coder apply
parents c23077d8 a7b96bde
<?php
/**
 * This is a helper class for the queue functionality.
 * It is a singleton class because it will hold the queue object for our extension
 *
 *
 */
*  * This is a helper class for the queue functionality.
*  * It is a singleton class because it will hold the queue object for our extension
*  *
*  *
 .*/
/*foreach (glob(__DIR__ . '/../../../../CRM/Core/*.php') as $filename)
{
require_once $filename;
}*/
/*set_include_path(get_include_path() . PATH_SEPARATOR . "/home/student/buildkit/build/my-drupal-civi47/sites/all/modules/civicrm");
require_once __DIR__ . '/../../../../CRM/Core/DAO.php';
foreach (glob(__DIR__ . '/../../../../CRM/Queue/*.php') as $filename)
{
require_once $filename;
}*/
//eval(`cv php:boot`);
class CRM_OSDIQueue_Helper
{
const QUEUE_NAME = 'com.civicrm.osdiqueue';
private $queue;
static $singleton;
private function __construct()
{
$this->queue = CRM_Queue_Service::singleton()->create(array(
'type' => 'Sql',
'name' => self::QUEUE_NAME,
'reset' => false, //do not flush queue upon creation
));
/**
*
*/
class CRM_OSDIQueue_Helper {
const QUEUE_NAME = 'com.civicrm.osdiqueue';
private $queue;
static $singleton;
/**
*
*/
private function __construct() {
$this->queue = CRM_Queue_Service::singleton()->create(array(
'type' => 'Sql',
'name' => self::QUEUE_NAME,
// Do not flush queue upon creation.
'reset' => FALSE,
));
}
/**
*
*/
public static function singleton() {
if (!self::$singleton) {
self::$singleton = new CRM_OSDIQueue_Helper();
}
return self::$singleton;
}
public static function singleton() {
if (!self::$singleton) self::$singleton = new CRM_OSDIQueue_Helper();
return self::$singleton;
}
/**
*
*/
public function getQueue() {
return $this->queue;
}
public function getQueue()
{
return $this->queue;
}
}
?>
This diff is collapsed.
<?php
return array(
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
'DE' => 'Delaware',
'DC' => 'Washington DC',
'FL' => 'Florida',
'GA' => 'Georgia',
'HI' => 'Hawaii',
'ID' => 'Idaho',
'IL' => 'Illinois',
'IN' => 'Indiana',
'IA' => 'Iowa',
'KS' => 'Kansas',
'KY' => 'Kentucky',
'LA' => 'Louisiana',
'ME' => 'Maine',
'MD' => 'Maryland',
'MA' => 'Massachusetts',
'MI' => 'Michigan',
'MN' => 'Minnesota',
'MS' => 'Mississippi',
'MO' => 'Missouri',
'MT' => 'Montana',
'NE' => 'Nebraska',
'NV' => 'Nevada',
'NH' => 'New Hampshire',
'NJ' => 'New Jersey',
'NM' => 'New Mexico',
'NY' => 'New York',
'NC' => 'North Carolina',
'ND' => 'North Dakota',
'OH' => 'Ohio',
'OK' => 'Oklahoma',
'OR' => 'Oregon',
'PA' => 'Pennsylvania',
'PR' => 'Puerto Rico',
'RI' => 'Rhode Island',
'SC' => 'South Carolina',
'SD' => 'South Dakota',
'TN' => 'Tennessee',
'TX' => 'Texas',
'UT' => 'Utah',
'VT' => 'Vermont',
'VI' => 'Virgin Islands',
'VA' => 'Virginia',
'WA' => 'Washington',
'WV' => 'West Virginia',
'WI' => 'Wisconsin',
'WY' => 'Wyoming',
);
?>
<?php
use CRM_Osdi_ExtensionUtil as E;
/**
*
*/
class CRM_Osdi_Page_Configure extends CRM_Core_Page {
/**
*
*/
public function run() {
// Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
// Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml.
CRM_Utils_System::setTitle(E::ts('Configure'));
parent::run();
......
<?php
use CRM_Osdi_ExtensionUtil as E;
/**
*
*/
class CRM_Osdi_Page_Mapping extends CRM_Core_Page {
/**
*
*/
public function run() {
// Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
// Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml.
CRM_Utils_System::setTitle(E::ts('Mapping'));
// grab fields for column1
// Grab fields for column1.
$names = array();
$firstitemid = civicrm_api3('Mapping', 'get', array(
'name' => "osdi_contact",
'name' => "osdi_contact",
));
$firstitem = civicrm_api3('MappingField', 'get', array(
'mapping_id' => $firstitemid["id"],
'sequential' => 1,
'options' => ['limit' => 0],
'mapping_id' => $firstitemid["id"],
'sequential' => 1,
'options' => ['limit' => 0],
));
foreach ($firstitem["values"] as $key => $value) {
$addOn = "";
if (substr($value["name"], 0, 6 ) == "custom") {
// grab the actual name too
$result = civicrm_api3('CustomField', 'get', array(
'sequential' => 1,
'id' => (int) substr($value["name"], 7)
));
$addOn = "/" . $result["values"][0]["name"];
}
$item = array();
$item["first"] = $value["name"];
$item["firstname"] = $value["name"] . $addOn;
$item["second"] = $value["value"];
$item["id"] = $value["id"];
$names[] = $item;
$addOn = "";
if (substr($value["name"], 0, 6) == "custom") {
// Grab the actual name too.
$result = civicrm_api3('CustomField', 'get', array(
'sequential' => 1,
'id' => (int) substr($value["name"], 7),
));
$addOn = "/" . $result["values"][0]["name"];
}
$item = array();
$item["first"] = $value["name"];
$item["firstname"] = $value["name"] . $addOn;
$item["second"] = $value["value"];
$item["id"] = $value["id"];
$names[] = $item;
}
$this->assign('names', $names);
......
<?php
// include the importer classes
//require_once __DIR__ . '/OSDIQueueHelper.php';
// Include the importer classes
// require_once __DIR__ . '/OSDIQueueHelper.php';.
require_once __DIR__ . '/../../../importers/ActionNetworkContactImporter.php';
use CRM_Osdi_ExtensionUtil as E;
/**
*
*/
class CRM_Osdi_Page_OSDI extends CRM_Core_Page {
/**
*
*/
public function run() {
// Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
// Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml.
CRM_Utils_System::setTitle(E::ts('OSDI'));
$configs = include('config.php');
$configs = include 'config.php';
$this->assign('taskNumber', '0');
$this->assign('taskNumber', '0');
$result = civicrm_api3('Importer', 'import', array(
'key' => $configs["key"]
));
$this->assign('taskNumber', $result["values"]["count"]);
$result = civicrm_api3('Importer', 'import', array(
'key' => $configs["key"],
));
$this->assign('taskNumber', $result["values"]["count"]);
//$importer = new ActionNetworkContactImporter("https://actionnetwork.org/api/v2", "x", $configs["key"]);
//$count = $importer->pull_endpoint_data();
$this->assign('completed', "yes");
// $importer = new ActionNetworkContactImporter("https://actionnetwork.org/api/v2", "x", $configs["key"]);
// $count = $importer->pull_endpoint_data();
$this->assign('completed', "yes");
parent::run();
}
......
<?php
use CRM_Osdi_ExtensionUtil as E;
class CRM_Osdi_Page_OSDIJob extends CRM_Core_Page {
public function run() {
$jobresults = civicrm_api3('Job', 'get', [
'sequential' => 1,
'name' => ['LIKE' => "OSDISYNC_IMPORT_%"]
]);
$jobs = array();
foreach ($jobresults["values"] as $job) {
$metadata = array();
// split and extract name
$metadata["name"] = substr($job["name"], 16);
// extract jobID
$metadata["id_import"] = $job["id"];
// extract joblog
$metadata["id_import_log"] = "No runs yet!";
$joblogresults = civicrm_api3("JobLog", "get", array(
"job_id" => $job["id"],
"options" => array("sort" => "run_time DESC"),
"sequential" => 1
));
if (sizeof($joblogresults["values"]) != 0) {
$metadata["id_import_log"] = substr($joblogresults["values"][0]["data"], 0, 500);
}
// extract groupID, ruleID
$metadata["group_id"] = "N/A";
$metadata["group_name"] = "";
// extract ruleID
$metadata["rule_id"] = "N/A";
$metadata["rule_fields"] = "";
$parameters = explode("\n", $job["parameters"]);
foreach($parameters as $parameter) {
$params = explode("=", $parameter);
if ($params[0] == "group") {
if ($params[1] != "") {
$results = civicrm_api3("Group", "get", [
"sequential" => 1,
"id" => $params[1]
]);
if (sizeof($results["values"] != 0)) {
$metadata["group_id"] = $results["values"][0]["id"];
$metadata["group_name"] = $results["values"][0]["name"];
}
}
}
if ($params[0] == "rule") {
if ($params[1] != "") {
$rulegetresults = civicrm_api3("Rule", "get", [
"sequential" => 1,
"dedupe_rule_group_id" => $params[1]
]);
if (sizeof($rulegetresults["values"]) != 0) {
$metadata["rule_id"] = $rulegetresults["values"][0]["id"];
foreach ($rulegetresults["values"] as $rulegetresult) {
$metadata["rule_fields"] = $metadata["rule_fields"] . $rulegetresult["rule_field"];
$metadata["rule_fields"] = $metadata["rule_fields"] . ", ";
}
}
}
}
if ($params[0] == "endpoint") {
$metadata["endpointname"] = $params[1];
}
}
// load the export value
$exportjobresults = civicrm_api3('Job', 'get', [
'sequential' => 1,
'name' => "OSDISYNC_EXPORT_" . $metadata["name"]
]);
if (sizeof($exportjobresults["values"]) != 0) {
$metadata["id_export"] = $exportjobresults["values"][0]["id"];
}
$metadata["id_export_log"] = "No runs yet!";
$joblogresults = civicrm_api3("JobLog", "get", array(
"job_id" => $metadata["id_export"],
"options" => array("sort" => "run_time DESC"),
"sequential" => 1
));
if (sizeof($joblogresults["values"]) != 0) {
$metadata["id_export_log"] = substr($joblogresults["values"][0]["data"], 0, 500);
}
// load all the metadata into the array
$jobs[] = $metadata;
}
$this->assign('jobs', $jobs);
parent::run();
}
}
<?php
use CRM_Osdi_ExtensionUtil as E;
/**
*
*/
class CRM_Osdi_Page_OSDIRunner extends CRM_Core_Page {
public function run() {
// Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
CRM_Utils_System::setTitle(E::ts('OSDIRunner'));
//retrieve the queue
$queue = CRM_OSDIQueue_Helper::singleton()->getQueue();
$runner = new CRM_Queue_Runner(array(
'title' => ts('OSDI Queue Page runner'), //title fo the queue
'queue' => $queue, //the queue object
'errorMode' => CRM_Queue_Runner::ERROR_ABORT, //abort upon error and keep task in queue
'onEnd' => array('CRM_OSDIQueue_Runner', 'onEnd'), //method which is called as soon as the queue is finished
'onEndUrl' => CRM_Utils_System::url('civicrm/xxxx', 'reset=0'), //go to page after all tasks are finished
));
$runner->runAllViaWeb(); // does not return
parent::run();
}
static function onEnd(CRM_Queue_TaskContext $ctx) {
//set a status message for the user
CRM_Core_Session::setStatus('All tasks in queue are executes', 'Queue', 'success');
}
/**
*
*/
public function run() {
// Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml.
CRM_Utils_System::setTitle(E::ts('OSDIRunner'));
// Retrieve the queue.
$queue = CRM_OSDIQueue_Helper::singleton()->getQueue();
$runner = new CRM_Queue_Runner(array(
// Title fo the queue.
'title' => ts('OSDI Queue Page runner'),
// The queue object.
'queue' => $queue,
// Abort upon error and keep task in queue.
'errorMode' => CRM_Queue_Runner::ERROR_ABORT,
// Method which is called as soon as the queue is finished.
'onEnd' => array('CRM_OSDIQueue_Runner', 'onEnd'),
// Go to page after all tasks are finished.
'onEndUrl' => CRM_Utils_System::url('civicrm/xxxx', 'reset=0'),
));
// Does not return.
$runner->runAllViaWeb();
parent::run();
}
/**
*
*/
public static function onEnd(CRM_Queue_TaskContext $ctx) {
// Set a status message for the user.
CRM_Core_Session::setStatus('All tasks in queue are executes', 'Queue', 'success');
}
}
This diff is collapsed.
<?php
/**
*
*/
class CRM_Osdi_Permission extends CRM_Core_Permission {
/**
......@@ -9,28 +12,31 @@ class CRM_Osdi_Permission extends CRM_Core_Permission {
* @return array Keyed by machine names with human-readable labels for values
*/
public static function getOsdiPermissions() {
$prefix = ts('OSDI sample application') . ': '; // name of extension or module
return array(
'allow webhook posts' => $prefix . ts('allow webhook posts'),
);
// Name of extension or module.
$prefix = ts('OSDI sample application') . ': ';
return array(
'allow webhook posts' => $prefix . ts('allow webhook posts'),
);
}
/**
* Given a permission string or array, check for access requirements.
* Given a permission string or array, check for access requirements.
* if this is a permissions-challenged Joomla instance, don't enforce
* CiviMailchimp-defined permissions.
*
* @param mixed $permissions The permission(s) to check as an array or string.
* See parent class for examples.
* @return boolean
* @param mixed $permissions
* The permission(s) to check as an array or string.
* See parent class for examples.
*
* @return bool
*/
public static function check($permissions) {
$permissions = (array) $permissions;
if (!CRM_Core_Config::singleton()->userPermissionClass->isModulePermissionSupported()) {
array_walk_recursive($permissions, function(&$v, $k) {
array_walk_recursive($permissions, function (&$v, $k) {
if (array_key_exists($v, CRM_Osdi_Permission::getOsdiPermissions())) {
$v = CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION;
}
......@@ -38,4 +44,5 @@ class CRM_Osdi_Permission extends CRM_Core_Permission {
}
return parent::check($permissions);
}
}
<?php
use CRM_Osdi_ExtensionUtil as E;
/**
* Collection of upgrade steps.
......@@ -8,15 +7,14 @@ class CRM_Osdi_Upgrader extends CRM_Osdi_Upgrader_Base {
// By convention, functions that look like "function upgrade_NNNN()" are
// upgrade tasks. They are executed in order (like Drupal's hook_update_N).
/**
* Example: Run an external SQL script when the module is installed.
*
public function install() {
$this->executeSqlFile('sql/myinstall.sql');
}
/**
* Public function install() {
* $this->executeSqlFile('sql/myinstall.sql');
* }
*
* /**
* Example: Work with entities usually not available during the install step.
*
* This method can be used for any post-install tasks. For example, if a step
......@@ -24,81 +22,84 @@ class CRM_Osdi_Upgrader extends CRM_Osdi_Upgrader_Base {
* created during the installation (e.g., a setting or a managed entity), do
* so here to avoid order of operation problems.
*
public function postInstall() {
$customFieldId = civicrm_api3('CustomField', 'getvalue', array(
'return' => array("id"),
'name' => "customFieldCreatedViaManagedHook",
));
civicrm_api3('Setting', 'create', array(
'myWeirdFieldSetting' => array('id' => $customFieldId, 'weirdness' => 1),
));
}
/**
* public function postInstall() {
* $customFieldId = civicrm_api3('CustomField', 'getvalue', array(
* 'return' => array("id"),
* 'name' => "customFieldCreatedViaManagedHook",
* ));
* civicrm_api3('Setting', 'create', array(
* 'myWeirdFieldSetting' => array('id' => $customFieldId, 'weirdness' => 1),
* ));
* }
*
* /**
* Example: Run an external SQL script when the module is uninstalled.
*
public function uninstall() {
$this->executeSqlFile('sql/myuninstall.sql');
}
/**
* public function uninstall() {
* $this->executeSqlFile('sql/myuninstall.sql');
* }
*
* /**
* Example: Run a simple query when a module is enabled.
*
public function enable() {
CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 1 WHERE bar = "whiz"');
}
/**
* public function enable() {
* CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 1 WHERE bar = "whiz"');
* }
*
* /**
* Example: Run a simple query when a module is disabled.
*
public function disable() {
CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 0 WHERE bar = "whiz"');
}
/**
* public function disable() {
* CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 0 WHERE bar = "whiz"');
* }
*
* /**
* Example: Run a couple simple queries.
*
* @return TRUE on success
*
* @throws Exception
*
public function upgrade_4200() {
$this->ctx->log->info('Applying update 4200');
CRM_Core_DAO::executeQuery('UPDATE foo SET bar = "whiz"');
CRM_Core_DAO::executeQuery('DELETE FROM bang WHERE willy = wonka(2)');
return TRUE;
} // */
* public function upgrade_4200() {
* $this->ctx->log->info('Applying update 4200');
* CRM_Core_DAO::executeQuery('UPDATE foo SET bar = "whiz"');
* CRM_Core_DAO::executeQuery('DELETE FROM bang WHERE willy = wonka(2)');
* return TRUE;
* } // */
/**
* Example: Run an external SQL script.
*
* @return TRUE on success
*
* @throws Exception
public function upgrade_4201() {
$this->ctx->log->info('Applying update 4201');
// this path is relative to the extension base dir
$this->executeSqlFile('sql/upgrade_4201.sql');
return TRUE;
} // */
* public function upgrade_4201() {
* $this->ctx->log->info('Applying update 4201');
* // this path is relative to the extension base dir
* $this->executeSqlFile('sql/upgrade_4201.sql');
* return TRUE;
* } // */
/**
* Example: Run a slow upgrade process by breaking it up into smaller chunk.
*
* @return TRUE on success
*
* @throws Exception
public function upgrade_4202() {
$this->ctx->log->info('Planning update 4202'); // PEAR Log interface
$this->addTask(E::ts('Process first step'), 'processPart1', $arg1, $arg2);
$this->addTask(E::ts('Process second step'), 'processPart2', $arg3, $arg4);
$this->addTask(E::ts('Process second step'), 'processPart3', $arg5);
return TRUE;
}
public function processPart1($arg1, $arg2) { sleep(10); return TRUE; }
public function processPart2($arg3, $arg4) { sleep(10); return TRUE; }
public function processPart3($arg5) { sleep(10); return TRUE; }
// */
* public function upgrade_4202() {
* $this->ctx->log->info('Planning update 4202'); // PEAR Log interface
*
* $this->addTask(E::ts('Process first step'), 'processPart1', $arg1, $arg2);
* $this->addTask(E::ts('Process second step'), 'processPart2', $arg3, $arg4);
* $this->addTask(E::ts('Process second step'), 'processPart3', $arg5);
* return TRUE;
* }
* public function processPart1($arg1, $arg2) { sleep(10); return TRUE; }
* public function processPart2($arg3, $arg4) { sleep(10); return TRUE; }
* public function processPart3($arg5) { sleep(10); return TRUE; }
* // */
/**
......@@ -106,29 +107,30 @@ class CRM_Osdi_Upgrader extends CRM_Osdi_Upgrader_Base {
* millions) of records by breaking it up into smaller chunks.
*
* @return TRUE on success
*
* @throws Exception
public function upgrade_4203() {
$this->ctx->log->info('Planning update 4203'); // PEAR Log interface
$minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contribution');
$maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contribution');
for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
$endId = $startId + self::BATCH_SIZE - 1;
$title = E::ts('Upgrade Batch (%1 => %2)', array(
1 => $startId,
2 => $endId,
));
$sql = '
UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
WHERE id BETWEEN %1 and %2
';
$params = array(
1 => array($startId, 'Integer'),
2 => array($endId, 'Integer'),
);
$this->addTask($title, 'executeSql', $sql, $params);
}
return TRUE;
} // */
* public function upgrade_4203() {
* $this->ctx->log->info('Planning update 4203'); // PEAR Log interface
*
* $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contribution');
* $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contribution');
* for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
* $endId = $startId + self::BATCH_SIZE - 1;
* $title = E::ts('Upgrade Batch (%1 => %2)', array(
* 1 => $startId,
* 2 => $endId,
* ));
* $sql = '
* UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
* WHERE id BETWEEN %1 and %2