Skip to content

Instantly share code, notes, and snippets.

View ginkgomzd's full-sized avatar

Michael Z Daryabeygi ginkgomzd

View GitHub Profile
@ginkgomzd
ginkgomzd / extract-field-mapping-by-id.php
Created December 8, 2015 21:27
Export CiviCRM Field mapping
#!/usr/bin/php
<?php
$usage = "Given the ID of a field mapping (e.g., for imports), returns the SQL "
. "required to import the mapping into another system. The output *should* be pipeable "
. "to mysql (not tested).\n\nExample: " . basename($argv[0]) . " <id>";
// TODO: if we did this as a drush script we could leave out all the DB stuff
// CONFIG //
$db_host = 'localhost';
$db_name = 'test_drupal7_civicrm';
diff --git a/CRM/ACL/BAO/ACL.php b/CRM/ACL/BAO/ACL.php
index 54962f9..205cb0b 100644
--- a/CRM/ACL/BAO/ACL.php
+++ b/CRM/ACL/BAO/ACL.php
@@ -723,14 +723,54 @@ SELECT count( a.id )
}
/**
+ * Build a join and where part for a query
+ *
@ginkgomzd
ginkgomzd / .htaccess-partial
Last active September 30, 2016 21:31
an htaccess cache router that works with drupal
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^ - [E=vka_api_cache:sites/default/files/api-cache]
# Enable back-door and skip the rewriting
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
@ginkgomzd
ginkgomzd / cron-build-caches.php
Created September 30, 2016 21:40
a cron job to build a month's worth of daily API requests
<?php
// MZD's JANKY CACHE
define('VKA_API_CACHE_DIR', '/home/vegeta85/public_html/sites/default/files/api-cache');
$types = array('recipes', 'days', 'images','test');
for ($d=1;$d < 32; $d++) {
$lastMonths = genFileNamesForDate($d, 'last');
if ($lastMonths === FALSE) continue;
-- Find suspect Memberships due to contributions being linked to multiple membership-payment records
SELECT
mempay.id AS mempay_id,
mempay.contribution_id AS contrib_id,
contrib.receive_date, contrib.total_amount,
mempay.membership_id AS mem_id, memtype.name,
c_contrib.display_name AS contrib_contact_name, c_contrib.id AS contrib_contact_id,
c_mem.id AS mem_contact_id, c_mem.display_name AS mem_contact_name
$participants = civicrm_api3('Participant', 'get', array(
'sequential' => 1,
'status_id' => "Registered",
'event_id' => array(
'IN' => $event_ids
),
// Get price set info if available in line below
'api.LineItem.get' => array('entity_table' => "civicrm_participant", 'entity_id' => "\$value.participant_id")
)) ['values'];
@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
SITE=sandbox-volunteer.leadercenter.org
HTDOCS=/home/leaderce/websites/$SITE/htdocs
DRUSH=/usr/local/bin/drush
pushd $HTDOCS > /dev/null
while read line ; do
read contact_id
$DRUSH cvapi --out=pretty \
@ginkgomzd
ginkgomzd / ansible-router
Last active June 3, 2017 19:59
make ansible appear as one command
#! /usr/bin/env bash
__print_completions() {
printf '%s\n' "${COMPREPLY[@]}"
}
# load bash-completion functions
source /etc/bash_completion
_ansible_wrapper() {
@ginkgomzd
ginkgomzd / List Enabled Error Reporting Flags.php
Last active June 16, 2017 20:02
Test or List PHP Error Reporting Flags
<?php
// example call, specifying bit-flags,
// returns as string:
echo listEnabledErrorReportingFlags(E_ALL & ~(E_WARNING|E_NOTICE|E_STRICT));
// example call, using current bit-flags,
// returns as array:
var_export(listEnabledErrorReportingFlags(null, TRUE));