Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions client_cards_plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,55 @@ public function __construct()
$this->loadConfig(dirname(__FILE__) . DS . 'config.json');
}

/**
* Performs migration of data from $current_version (the current installed version)
* to the given file set version
*
* @param string $current_version The current installed version of this plugin
* @param int $plugin_id The ID of the plugin being upgraded
*/
public function upgrade($current_version, $plugin_id)
{
if (!isset($this->Record)) {
Loader::loadComponents($this, ['Record']);
}

// Upgrade to 1.3.0
if (version_compare($current_version, '1.3.0', '<')) {
$this->updateCardColors();
}
}

/**
* Updates the default card background colors to match the Meridian palette
* (services -> primary blue, invoices -> warning amber). Only cards still using the
* previous default colors are updated, preserving any admin customizations.
*/
private function updateCardColors()
{
// Map the previous default backgrounds to the new Meridian palette
$colors = ['#ffc107' => '#2563eb', '#28a746' => '#d97706'];

// Gather this plugin's instances across all companies
$plugins = $this->Record->select(['id'])
->from('plugins')
->where('dir', '=', 'client_cards')
->fetchAll();
$plugin_ids = array_map(function ($plugin) {
return $plugin->id;
}, $plugins);

if (empty($plugin_ids)) {
return;
}

foreach ($colors as $from => $to) {
$this->Record->where('plugin_id', 'in', $plugin_ids)
->where('background', '=', $from)
->update('plugin_cards', ['background' => $to]);
}
}

/**
* Retrieves the total number of active and suspended services
*
Expand Down Expand Up @@ -79,9 +128,10 @@ public function getCards()
'callback' => ['this', 'getServicesCount'],
'callback_type' => 'value',
'label' => 'ClientCardsPlugin.card_client.services',
'text_color' => '#fffaeb',
'background' => '#ffc107',
'text_color' => '#ffffff',
'background' => '#2563eb',
'background_type' => 'color',
'icon' => 'bi bi-hdd-stack',
'link' => 'services/index/active/',
'enabled' => 1
],
Expand All @@ -90,9 +140,10 @@ public function getCards()
'callback' => ['this', 'getInvoicesCount'],
'callback_type' => 'value',
'label' => 'ClientCardsPlugin.card_client.invoices',
'text_color' => '#e4f5e7',
'background' => '#28a746',
'text_color' => '#ffffff',
'background' => '#d97706',
'background_type' => 'color',
'icon' => 'bi bi-receipt',
'link' => 'invoices/index/open/',
'enabled' => 1
]
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.2.0",
"version": "1.3.0",
"name": "ClientCardsPlugin.name",
"description": "ClientCardsPlugin.description",
"authors": [
Expand Down