Skip to content

Instantly share code, notes, and snippets.

View ginkgomzd's full-sized avatar

Michael Z Daryabeygi ginkgomzd

View GitHub Profile
@ginkgomzd
ginkgomzd / recurrence_engine.sql
Created May 2, 2014 17:58
a sql approach to translating recurrence rules to a database object to translate rules into date series virtually. in response to http://wiki.civicrm.org/confluence/display/CRM/Recurring+Entities+Specification
/*
DROP TABLE IF EXISTS days;
CREATE TABLE days (
day_of_year int NOT NULL
);
DROP TABLE IF EXISTS recurrence_rules;
CREATE TABLE recurrence_rules (
@ginkgomzd
ginkgomzd / find_inbound_email_activities.sql
Last active August 29, 2015 14:04
Reassign Inbound Emails
CREATE ALGORITHM=UNDEFINED DEFINER=`mzd`@`localhost` SQL SECURITY DEFINER VIEW `find_inbound_emails`
AS select
`opt`.`name` AS `record_type`
,`ac`.`record_type_id` AS `record_type_id`
,`act`.`id` AS `id`
,`act`.`subject` AS `subject`
,`act`.`activity_date_time` AS `activity_date_time`
,`ac`.`contact_id` AS `contact_id`
,`cont`.`display_name` AS `display_name`
FROM (((`civicrm_activity` `act`
@ginkgomzd
ginkgomzd / civicrm_api3_exception.php
Last active February 24, 2017 00:56
CiviCRM catch API3_Exception Pattern
<?php
/***
* Suggestion for a utility function or pattern for API Exceptions
***/
$params = array(
'name' => $optionName,
'label' => ts($optionLabel, array('domain' => 'org.civicrm')),
'option_group_id' => null, // so it will cause an exception
#!/usr/bin/php
<?php
/***
* generates xml config for import to civicrm as Option Group Values
*
* cat interests.html | ./parse-interests-options-values.php > xml/option_values.xml
*
* STDIN should be html Select-list, each option on a line
***/
@ginkgomzd
ginkgomzd / unsubscribe victory-kit emails.sql
Last active August 29, 2015 14:04
query snippits for updating unsubscribed status in victory-kit
-- SELECT count(*) from unsubscribes uns INNER JOIN import_unsubscribes_aug5 imp on uns.email = imp.email
--DELETE FROM import_unsubscribes_aug5 where email in (SELECT DISTINCT email from unsubscribes);
INSERT INTO unsubscribes (
SELECT nextval('unsubscribes_id_seq'), uns.email, 'manual-unsub', sent.member_id, now(), now(), null, null, sent_id
FROM
import_unsubscribes_aug5 uns
INNER JOIN
@ginkgomzd
ginkgomzd / civix_conf_db.sh
Created August 10, 2014 18:07
configure civix db connection with a bash function
civix_conf_db() {
conf_path=`readlink -f $1`
echo "setting civicrm_api3_conf_path to $conf_path"
civix config:set civicrm_api3_conf_path $conf_path
civix civicrm:ping
}
@ginkgomzd
ginkgomzd / findFullPathInArray
Created October 30, 2014 13:54
Find the full path to a unique key in a multidimensional array
function findFullPathInArray($array, $search, $path=array()) {
if (!is_array($array)) return FALSE;
$try_path = $path;
foreach($array as $key => $item) {
if ($key == $search) { // found
$path[] = $search;
return $path;
}
$try_path[] = $key;
@ginkgomzd
ginkgomzd / gen-db-prefix.php
Created December 16, 2014 13:25
generate drupal db prefix
#!/usr/bin/php
<?php
$sql = 'show tables';
$db = $argv[1];
$tables = array();
exec("echo '$sql' | mysql $db", $tables);
$prefix = <<<'TPL'
<?php
@ginkgomzd
ginkgomzd / confirm
Created January 13, 2015 19:15
confirm appointment
var ConfirmRouteBase = {
getParams: function() {
var ctlSchedule = this.controllerFor('schedule');
this.data = ctlSchedule.get('userInput');
this.data.email_optin = 1;
this.data.occurrence_id = ctlSchedule.get('appointment').id;
this.data.sms_optin = 1;
return this.data;
@ginkgomzd
ginkgomzd / cli.class.php.patch
Created May 26, 2015 15:58
patch to add json output option to cli.php
diff --git a/bin/cli.class.php b/bin/cli.class.php
index de72c47..5906656 100644
--- a/bin/cli.class.php
+++ b/bin/cli.class.php
@@ -45,6 +45,7 @@ class civicrm_cli {
var $_entity = NULL;
var $_action = NULL;
var $_output = FALSE;
+ var $_json = FALSE;
var $_joblog = FALSE;