executeSqlFile('sql/civicrm_twingle_profile.sql'); // add a default profile CRM_Twingle_Profile::createDefaultProfile()->saveProfile(); } /** * Example: Run an external SQL script when the module is uninstalled. * * public function uninstall() { * $this->executeSqlFile('sql/myuninstall.sql'); * } * * /** * Copy financial_type_id setting to new setting financial_type_id_recur. */ public function upgrade_4000(): bool { $this->ctx->log->info('Applying update 4000: Copying Financial type to new setting Financial type (recurring).'); foreach (CRM_Twingle_Profile::getProfiles() as $profile) { $profile->setAttribute('financial_type_id_recur', $profile->getAttribute('financial_type_id')); $profile->saveProfile(); } return TRUE; } /** * Convert serialized settings from objects to arrays. * * @link https://civicrm.org/advisory/civi-sa-2019-21-poi-saved-search-and-report-instance-apis */ public function upgrade_5011(): bool { // Do not use CRM_Core_BAO::getItem() or Civi::settings()->get(). // Extract and unserialize directly from the database. $twingle_profiles_query = CRM_Core_DAO::executeQuery(" SELECT `value` FROM `civicrm_setting` WHERE `name` = 'twingle_profiles';"); if ($twingle_profiles_query->fetch()) { $profiles = unserialize($twingle_profiles_query->value); Civi::settings()->set('twingle_profiles', (array) $profiles); } return TRUE; } /** * Upgrading to 1.4.0 needs to convert the profiles into the new infrastructure * * @return TRUE on success * @throws Exception */ public function upgrade_5140(): bool { $this->ctx->log->info('Converting twingle profiles.'); // create a DB table for the twingle profiles $this->executeSqlFile('sql/civicrm_twingle_profile.sql'); // migrate the current profiles if (is_array($profiles_data = Civi::settings()->get('twingle_profiles'))) { foreach ($profiles_data as $profile_name => $profile_data) { $profile = new CRM_Twingle_Profile($profile_name, $profile_data); $data = json_encode($profile->getData()); CRM_Core_DAO::executeQuery(<< [$profile_name, 'String'], 2 => [$data, 'String'], ]); } } return TRUE; } }