Removed unnecessary models since information will be fetched directly from the mailchimp API each time.

Signed-off-by: objec <objecttothis@gmail.com>
This commit is contained in:
objec
2026-04-22 17:00:34 +04:00
parent bae361c637
commit ec139c477a
4 changed files with 3 additions and 113 deletions

View File

@@ -1,34 +0,0 @@
<?php
namespace App\Plugins\MailchimpPlugin\Entities;
use CodeIgniter\Entity\Entity;
class Subscription extends Entity
{
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $casts = [
'customer_id' => 'integer',
'mailchimp_id' => 'string',
'status_id' => 'enum[App\Plugins\MailchimpPlugin\Enums\SubscriptionStatus]',
'created_at' => 'datetime',
'updated_at' => '?datetime',
'deleted_at' => '?datetime'
];
protected $attributes = [
'customer_id' => null, // ospos_customers.person_id
'mailchimp_id' => null, // MD5 hash of the lowercase version of the list member's email address
'status_id' => null, // ospos_mailchimpplugin_subscription_status.status_id
'created_at' => null, // Timestamp of when the subscription was created
'updated_at' => null, // Timestamp of when the subscription was last updated
'deleted_at' => null // Timestamp of when the subscription was deleted
];
public function setMailchimpId(string $email)
{
$this->attributes['mailchimp_id'] = md5(strtolower($email));
return $this;
}
}

View File

@@ -4,8 +4,10 @@ namespace App\Plugins\MailchimpPlugin;
use App\Libraries\Plugins\BasePlugin;
use App\Plugins\MailchimpPlugin\Libraries\MailchimpLibrary;
use CodeIgniter\Database\RawSql;
use CodeIgniter\Events\Events;
use CodeIgniter\HTTP\ResponseInterface;
use Config\Database;
use Config\Services;
use stdClass;
@@ -69,6 +71,7 @@ class MailchimpPlugin extends BasePlugin
public function uninstall(): bool
{
log_message('info', 'Uninstalling Mailchimp plugin');
return true;
}

View File

@@ -1,49 +0,0 @@
<?php
namespace App\Plugins\MailchimpPlugin\Models;
use App\Plugins\MailchimpPlugin\Entities\Subscription;
use CodeIgniter\Model;
use ReflectionException;
class SubscriptionModel extends Model
{
protected $table = 'mailchimpplugin_subscriptions';
protected $primaryKey = 'customer_id';
protected $useAutoIncrement = false;
protected $returnType = Subscription::class;
protected $useSoftDeletes = true;
protected $allowedFields = [
'mailchimp_id', // MD5 hash of the lowercase version of the list member's email address
'status_id', // ospos_mailchimpplugin_subscription_status.status_id
'created_at', // Timestamp of when the subscription was created
'updated_at', // Timestamp of when the subscription was last updated
'deleted_at' // Timestamp of when the subscription was deleted
];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
public function upsert(array $customerData): int|false
{
try {
if ($this->save($customerData)) {
return $customerData[$this->primaryKey] ?? $this->getInsertID();
}
} catch (ReflectionException $e) {
log_message('error', 'Subscription upsert failed: ' . $e->getMessage());
}
return false;
}
public function exists(?int $customerId): bool
{
if (!is_int($customerId) || $customerId < 1) {
return false;
}
$builder = $this->db->table($this->table);
$builder->where('customer_id', $customerId);
return ($builder->countAllResults() === 1);
}
}

View File

@@ -1,30 +0,0 @@
<?php
namespace App\Plugins\MailchimpPlugin\Models;
use CodeIgniter\Model;
class SubscriptionStatusModel extends Model
{
protected $table = 'mailchimpplugin_subscription_status';
protected $primaryKey = 'status_id';
protected $useAutoIncrement = false;
protected $useSoftDeletes = false;
protected $returnType = 'array';
protected $allowedFields = [
'status_name'
];
public function getStatusIdByName(string $name): ?int
{
$row = $this->where('status_name', $name)->first();
return $row['status_id'] ?? null;
}
public function getStatusNameById(int $id): ?string
{
$row = $this->find($id);
return $row['status_name'] ?? null;
}
}