Skip to content

Instantly share code, notes, and snippets.

@MegaphoneJon
MegaphoneJon / sharedaddresssync.php
Created October 2, 2014 15:28
CiviCRM shared address sync module
<?php
require_once 'sharedaddressstatussync.civix.php';
function sharedaddressstatussync_civicrm_custom( $op, $groupID, $entityID, &$params ) {
//if a master address' location type is changed to "Bad Address", set the shared address' location type to same.
if ($op == 'edit') {
//Custom Group ID for Address Status is 5.
if($groupID == 5) {
$status = $params[0]['value'];
@MegaphoneJon
MegaphoneJon / backupninja_icinga2.sh
Last active February 16, 2017 18:18
Icinga2 integration into backupninja
function generate_post_data() {
cat <<EOF
{
"exit_status": $EXIT_STATUS,
"plugin_output": "$PLUGIN_OUTPUT"
}
EOF
}
function generate_post_reschedule() {
--- mysql.orig 2016-02-20 14:31:25.601574577 -0500
+++ mysql 2016-02-20 14:52:32.685574577 -0500
@@ -238,14 +238,14 @@
then
if [ $usevserver = yes ]
then
- debug 'set -o pipefail ; echo show databases | $VSERVER $vsname exec su $user -c \"$MYSQL $defaultsfile\" | grep -v Database'
- databases=`set -o pipefail ; echo 'show databases' | $VSERVER $vsname exec su $user -c "$MYSQL $defaultsfile" | grep -v Database`
+ debug 'set -o pipefail ; echo show databases | $VSERVER $vsname exec su $user -c \"$MYSQL $defaultsfile\" | grep -v Database | grep -v '^\(information\|performance\)_schema$''
+ databases=`set -o pipefail ; echo 'show databases' | $VSERVER $vsname exec su $user -c "$MYSQL $defaultsfile" | grep -v Database | grep -v '^\(information\|performance\)_schema$'`
@MegaphoneJon
MegaphoneJon / Kettle experiment
Created July 2, 2018 00:03
This is some code I was writing to test changing field names in Kettle with the UJDC step. Turns out you really need the ETL Metadata Injection step or nothing to change field names.
//Fields.In is a rowMetaInterface.
// We want to call the setName method of the valueMetaInterface, which we can grab from rowMetaInterface.
private FieldHelper inputField = null;
private ValueMetaInterface vMeta = null;
private int index;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
// Get a row from the stream.
Object[] r = getRow();
@MegaphoneJon
MegaphoneJon / grantexpensepatch.diff
Last active September 8, 2019 01:51
Hack to allow selecting Grant Expense Accounts since PR#14058 was rejected
--- a/CRM/Financial/BAO/FinancialAccount.php
+++ b/CRM/Financial/BAO/FinancialAccount.php
@@ -292,6 +292,7 @@
'Discounts Account is' => 'Revenue',
'Sales Tax Account is' => 'Liability',
'Deferred Revenue Account is' => 'Liability',
+ 'Grant Expense Account is' => 'Expenses',
];
if (!$flip) {
foreach ($Links as $accountRelation => $accountType) {
@MegaphoneJon
MegaphoneJon / gist:6e49eb4f0cfbae362202166cf700573c
Last active August 14, 2019 04:03
RimWorld Hardcore SK bugs to evaluate
* -UI zoom=in places work jobs in the wrong place on the UI (RimThemesLite? Work tab vertical text option?)- [This is a known issue](https://github.com/fluffy-mods/WorkTab/issues/77)
* Methadone doesn't work?
* Animals aren't affected by cold?
@MegaphoneJon
MegaphoneJon / smartgroupprofiling.php
Created September 3, 2019 15:19
CiviCRM Smart group profiling
#!/usr/bin/php
<?php
// Use this code to see how long it takes to generate all of your smart groups to find slow ones.
eval(`cv php:boot`);
//Force a refresh of the cache
$sql = 'UPDATE civicrm_group SET cache_date = NULL, refresh_date = NULL';
CRM_Core_DAO::executeQuery($sql);
// Get a list of smart group IDs.
$smartGroups = civicrm_api3('Group', 'get', [
'return' => ["id", "title"],
@MegaphoneJon
MegaphoneJon / profiling.php
Created September 3, 2019 15:20
CiviCRM speed profiling script
#!/usr/bin/php
<?php
// How long does it take to create 10 contacts?
eval(`cv php:boot`);
\CRM_Core_Config::singleton()->doNotResetCache = 1;
//place this before any script you want to calculate time
$time_start = microtime(true);
$startTime = date('H:i:s');
@MegaphoneJon
MegaphoneJon / failedtest.php
Created November 14, 2019 17:07
I tried and failed to write a CiviCRM ReportTemplate test that relied on custom fields.
+ /**
+ * Ensure that a LEFT JOIN to a 1-to-many table doesn't multiply the statistics (reporting#21).
+ */
+ public function testContributionDetailStatisticsMultiRecordCustomField() {
+ $customGroup = $this->CustomGroupMultipleCreateWithFields();
+ $contactID = $this->individualCreate();
+ $params = [
+ 'entity_id' => $contactID,
+ 'custom_' . $customGroup['custom_field_id'][0] => 'value 1',
+ ];
diff --git a/CRM/Export/Form/Select.php b/CRM/Export/Form/Select.php
index 182e4fdba8..2fa668f950 100644
--- a/CRM/Export/Form/Select.php
+++ b/CRM/Export/Form/Select.php
@@ -231,11 +231,23 @@ FROM {$this->_componentTable}
$this->assign('totalSelectedRecords', $rowCount);
}
+ // If you have a large export and transfer data via $this->get() or $this->set(),
+ // it can overwhelm session storage limits. Use a temporary space.