🧹 code cleanup

This commit is contained in:
Marc Michalsky forumZFD 2021-04-12 11:26:29 +02:00
parent 9b45d4a1fa
commit 2f1e5721c1
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
7 changed files with 18 additions and 36 deletions

View file

@ -26,7 +26,6 @@ abstract class CRM_TwingleCampaign_BAO_Campaign {
protected $formattedValues; protected $formattedValues;
/** /**
* ## Campaign constructor. * ## Campaign constructor.
* *
@ -55,7 +54,6 @@ abstract class CRM_TwingleCampaign_BAO_Campaign {
* @throws \Exception * @throws \Exception
*/ */
public function create(bool $no_hook = FALSE): bool { public function create(bool $no_hook = FALSE): bool {
// Prepare project values for import into database // Prepare project values for import into database
$values_prepared_for_import = $this->values; $values_prepared_for_import = $this->values;
$this->formatValues( $this->formatValues(

View file

@ -27,6 +27,9 @@ class CRM_TwingleCampaign_BAO_CampaignType {
} }
/** /**
* @param bool $upgrade
* If true: Does not show UF message if campaign type already exists
*
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
*/ */
public function create(bool $upgrade = false) { public function create(bool $upgrade = false) {
@ -41,8 +44,7 @@ class CRM_TwingleCampaign_BAO_CampaignType {
] ]
); );
if ($field['count'] == 0) if ($field['count'] == 0) {
{
$this->results = civicrm_api3('OptionValue', 'create', $this->getSetAttributes()); $this->results = civicrm_api3('OptionValue', 'create', $this->getSetAttributes());
$this->value = array_column($this->results['values'], 'value')[0]; $this->value = array_column($this->results['values'], 'value')[0];
@ -55,8 +57,7 @@ class CRM_TwingleCampaign_BAO_CampaignType {
} }
else { else {
$error_message = $this->results['error_message']; $error_message = $this->results['error_message'];
Civi::log()->error("Twingle Extension could not create new campaign type Civi::log()->error("Twingle Extension could not create new campaign type for \"$this->label\": $error_message");
for \"$this->label\": $error_message");
} }
} }
elseif (!$upgrade) { elseif (!$upgrade) {

View file

@ -53,11 +53,6 @@ class CRM_TwingleCampaign_BAO_CustomField {
if (array_key_exists($var, $attributes)) { if (array_key_exists($var, $attributes)) {
$this->$var = $attributes[$var]; $this->$var = $attributes[$var];
} }
// translate help_post
if ($this->help_post) {
$this->help_post = E::ts($this->help_post);
}
} }
} }
@ -162,16 +157,9 @@ class CRM_TwingleCampaign_BAO_CustomField {
if (!$name) { if (!$name) {
$result = []; $result = [];
// Get json file with all custom fields for this extension // Get array with all custom fields for this extension
$json_file = file_get_contents(E::path() . $campaign_info =
'/CRM/TwingleCampaign/resources/campaigns.json'); require E::path() . '/CRM/TwingleCampaign/resources/campaigns.php';
$campaign_info = json_decode($json_file, TRUE);
// Log an error and throw an exception if the file cannot get read
if (!$campaign_info) {
Civi::log()->error("Could not read json file");
throw new Exception('Could not read json file');
}
// Recursive method call with all custom field names from the json file // Recursive method call with all custom field names from the json file
foreach ($campaign_info['custom_fields'] as $customField) { foreach ($campaign_info['custom_fields'] as $customField) {

View file

@ -33,11 +33,6 @@ class CRM_TwingleCampaign_BAO_OptionValue {
if (array_key_exists($var, $attributes)) { if (array_key_exists($var, $attributes)) {
$this->$var = $attributes[$var]; $this->$var = $attributes[$var];
} }
// translate description
if ($this->description) {
$this->description = E::ts($this->description);
}
} }
} }

View file

@ -677,19 +677,16 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
return $response; return $response;
} }
/** /**
* ## Last update * ## Last update
* Returns a timestamp of the last update of the TwingleProject campaign. * Returns a timestamp of the last update of the TwingleProject campaign.
* *
* @return int|string|null * @return int|null
*/ */
public public function lastUpdate(): ?int {
function lastUpdate(): ?int {
return self::getTimestamp($this->values['last_update']); return self::getTimestamp($this->values['last_update']);
} }
/** /**
* ## Get project id * ## Get project id
* Returns the **project_id** of this TwingleProject. * Returns the **project_id** of this TwingleProject.

View file

@ -65,10 +65,12 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
*/ */
public function install() { public function install() {
// Create campaign types, custom fields and custom groups by the contents // Create campaign types, custom fields and custom groups by the contents
// of the json file "campaigns.json" // of the campaigns.php file
$campaign_info = Cache::getInstance()->getCampaigns(); $campaign_info = require E::path() .
$option_values = Cache::getInstance()->getOptionValues(); '/CRM/TwingleCampaign/resources/campaigns.php';
$option_values = require E::path() .
'/CRM/TwingleCampaign/resources/option_values.php';
// Create campaign types // Create campaign types
foreach ($campaign_info['campaign_types'] as $campaign_type) { foreach ($campaign_info['campaign_types'] as $campaign_type) {
@ -132,7 +134,8 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
*/ */
public function uninstall() { public function uninstall() {
$campaign_info = Cache::getInstance()->getCampaigns(); $campaign_info = require E::path() .
'/CRM/TwingleCampaign/resources/campaigns.php';
$option_values = Cache::getInstance()->getOptionValues(); $option_values = Cache::getInstance()->getOptionValues();
// Delete campaign types // Delete campaign types