}
+ /**
+ * Re-save any valid values from contribute settings into the normal setting
+ * format.
+ *
+ * We render the array of contribution_invoice_settings and any that have
+ * metadata defined we add to the correct key. This is safe to run even if no
+ * settings are to be converted, per the test in
+ * testConvertUpgradeContributeSettings.
+ *
+ * @param $ctx
+ *
+ * @return bool
+ */
+ public static function updateContributeSettings($ctx) {
+ $settings = Civi::settings()->get('contribution_invoice_settings');
+ $metadata = \Civi\Core\SettingsMetadata::getMetadata();
+ $conversions = array_intersect_key((array) $settings, $metadata);
+ foreach ($conversions as $key => $conversion) {
+ Civi::settings()->set($key, $conversion);
+ }
+ return TRUE;
+ }
+
/**
* Do any relevant smart group updates.
*
* (change the x in the function name):
*/
- // /**
- // * Upgrade function.
- // *
- // * @param string $rev
- // */
- // public function upgrade_5_0_x($rev) {
- // $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
- // $this->addTask('Do the foo change', 'taskFoo', ...);
- // // Additional tasks here...
- // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
- // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
- // }
-
- // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
- // return TRUE;
- // }
+ /**
+ * Upgrade function.
+ *
+ * @param string $rev
+ */
+ public function upgrade_5_15_alpha1($rev) {
+ $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
+ $this->addTask('Fix errant deferred revenue settings', 'updateContributeSettings');
+ }
}
$this->assertEquals("$ 200.00 - STUDENT", $activity->subject, 'Check for total amount in activity.');
}
- /**
- * Test checkContributeSettings.
- */
- public function testCheckContributeSettings() {
- $settings = Civi::settings()->get('deferred_revenue_enabled');
- $this->assertNull($settings);
- $params = array(
- 'contribution_invoice_settings' => array(
- 'deferred_revenue_enabled' => '1',
- ),
- );
- $this->callAPISuccess('Setting', 'create', $params);
- $settings = Civi::settings()->get('deferred_revenue_enabled');
- $this->assertEquals($settings, 1, 'Check for settings has failed');
- }
-
/**
* Test allowUpdateRevenueRecognitionDate.
*/
* Test for validating financial type has deferred revenue account relationship.
*/
public function testcheckFinancialTypeHasDeferred() {
- Civi::settings()->set('contribution_invoice_settings', array('deferred_revenue_enabled' => '1'));
- $params = array();
+ Civi::settings()->set('deferred_revenue_enabled', 1);
+ $params = [];
$valid = CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params);
$this->assertFalse($valid, "This should have been false");
$cid = $this->individualCreate();
/**
* Test renaming multiple fields.
+ *
+ * @throws Exception
*/
public function testRenameFields() {
$this->callAPISuccess('SavedSearch', 'create', [
$this->assertEquals('activity_date_time_relative', $savedSearch['form_values'][1][0]);
}
+ /**
+ * Test that a mis-saved variable in 'contribute settings' can be converted to a
+ * 'proper' setting.
+ */
+ public function testConvertUpgradeContributeSettings() {
+ Civi::settings()->set('contribution_invoice_settings', ['foo' => 'bar', 'deferred_revenue_enabled' => 1]);
+ $this->assertEquals(0, Civi::settings()->get('deferred_revenue_enabled'));
+ CRM_Upgrade_Incremental_Base::updateContributeSettings(NULL, 5.1);
+ $this->assertEquals(1, Civi::settings()->get('deferred_revenue_enabled'));
+ }
+
}