feat(cloudron): add tirreno package artifacts

- Add CloudronStack/output/CloudronPackages-Artifacts/tirreno/ directory and its contents
- Includes package manifest, Dockerfile, source code, documentation, and build artifacts
- Add tirreno-1761840148.tar.gz as a build artifact
- Add tirreno-cloudron-package-1761841304.tar.gz as the Cloudron package
- Include all necessary files for the tirreno Cloudron package

This adds the complete tirreno Cloudron package artifacts to the repository.
This commit is contained in:
2025-10-30 11:43:06 -05:00
parent 0ce353ea9d
commit 91d52d2de5
1692 changed files with 202851 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Models\Enrichment;
class Base {
public function queryParams(): array {
$properties = get_object_vars($this);
$modifiedArray = [];
foreach ($properties as $key => $value) {
$modifiedArray[':' . $key] = $value;
}
return $modifiedArray;
}
public function slimIds(array $ids): array {
$filtered = array_filter($ids, static function ($value): bool {
return $value !== null;
});
return array_unique($filtered);
}
public function updateStringByPlaceholders(array $placeholders): string {
$transformed = array_map(static function ($item): string {
$key = ltrim($item, ':');
return "{$key} = {$item}";
}, $placeholders);
return implode(', ', $transformed);
}
public function validateIP(string $ip): bool {
return filter_var($ip, FILTER_VALIDATE_IP) !== false;
}
// Validate date
public function validateDate(string $date, string $format = 'Y-m-d'): bool {
$d = \DateTime::createFromFormat($format, $date);
return $d && $d->format($format) === $date;
}
public function validateDates(array $dates): bool {
foreach ($dates as $date) {
if ($date !== null && !$this->validateDate($date)) {
return false;
}
}
return true;
}
public function validateCidr(string $cidr): bool {
$parts = explode('/', $cidr);
if (count($parts) !== 2) {
return false;
}
$ip = $parts[0];
$netmask = intval($parts[1]);
if ($netmask < 0) {
return false;
}
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return $netmask <= 32;
}
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return $netmask <= 128;
}
return false;
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Models\Enrichment;
class Device extends \Models\Enrichment\Base {
protected string $ua;
protected ?string $device;
protected ?string $browser_name;
protected ?string $browser_version;
protected ?string $os_name;
protected ?string $os_version;
protected bool $modified;
protected bool $checked = true;
public function __construct() {
}
public function init(array $data): void {
$this->ua = $data['ua'];
$this->device = $data['device'];
$this->browser_name = $data['browser_name'];
$this->browser_version = $data['browser_version'];
$this->os_name = $data['os_name'];
$this->os_version = $data['os_version'];
$this->modified = $data['modified'];
}
public function prepareUpdate(): array {
$params = $this->queryParams();
unset($params[':ua']);
$placeholders = array_keys($params);
$updateString = $this->updateStringByPlaceholders($placeholders);
return [$params, $updateString];
}
public function updateEntityInDb(int $entityId, int $apiKey): void {
// total_visit and total_account should remain still
[$params, $updateString] = $this->prepareUpdate();
$params['entity_id'] = $entityId;
$params['key'] = $apiKey;
$query = ("
UPDATE event_ua_parsed
SET {$updateString}
WHERE
event_ua_parsed.id = :entity_id AND
event_ua_parsed.key = :key
");
$model = new \Models\Device();
$model->execQuery($query, $params);
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Models\Enrichment;
class DomainFound extends \Models\Enrichment\Base {
protected string $domain;
protected bool $blockdomains;
protected bool $disposable_domains;
protected bool $free_email_provider;
protected ?string $creation_date; // date
protected ?string $expiration_date; // date
protected ?int $return_code;
protected bool $disabled;
protected ?string $closest_snapshot; // date
protected bool $mx_record;
protected ?string $ip; // ipvanyaddress
protected ?string $geo_ip;
protected ?string $geo_html;
protected ?string $web_server;
protected ?string $hostname;
protected ?string $emails;
protected ?string $phone;
protected string $discovery_date; // date
protected ?int $tranco_rank;
protected bool $checked = true;
public function init(array $data): void {
$this->domain = $data['domain'];
$this->blockdomains = $data['blockdomains'];
$this->disposable_domains = $data['disposable_domains'];
$this->free_email_provider = $data['free_email_provider'];
$this->creation_date = $data['creation_date'];
$this->expiration_date = $data['expiration_date'];
$this->return_code = $data['return_code'];
$this->disabled = $data['disabled'];
$this->closest_snapshot = $data['closest_snapshot'];
$this->mx_record = $data['mx_record'];
$this->ip = $data['ip'];
$this->geo_ip = $data['geo_ip'];
$this->geo_html = $data['geo_html'];
$this->web_server = $data['web_server'];
$this->hostname = $data['hostname'];
$this->emails = $data['emails'];
$this->phone = $data['phone'];
$this->discovery_date = $data['discovery_date'];
$this->tranco_rank = $data['tranco_rank'];
$dates = [$this->creation_date, $this->expiration_date, $this->closest_snapshot, $this->discovery_date];
if (($this->ip && !$this->validateIP($this->ip)) || !$this->validateDates($dates)) {
throw new \Exception('Validation failed');
}
}
public function prepareUpdate(): array {
$params = $this->queryParams();
unset($params[':domain']);
$placeholders = array_keys($params);
$updateString = $this->updateStringByPlaceholders($placeholders);
return [$params, $updateString];
}
public function updateEntityInDb(int $entityId, int $apiKey): void {
// total_visit and total_account should remain still
[$params, $updateString] = $this->prepareUpdate();
$params['entity_id'] = $entityId;
$params['key'] = $apiKey;
$query = ("
UPDATE event_domain
SET {$updateString}
WHERE
event_domain.id = :entity_id AND
event_domain.key = :key
");
$model = new \Models\Domain();
$model->execQuery($query, $params);
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Models\Enrichment;
class DomainNotFound extends \Models\Enrichment\Base {
protected string $domain;
protected bool $blockdomains;
protected bool $disposable_domains;
protected bool $free_email_provider;
protected ?string $creation_date; // date
protected ?string $expiration_date; // date
protected ?int $return_code;
protected bool $disabled;
protected ?string $closest_snapshot; // date
protected bool $mx_record;
protected bool $checked = true;
public function __construct() {
}
public function init(array $data): void {
$this->domain = $data['domain'];
$this->blockdomains = $data['blockdomains'];
$this->disposable_domains = $data['disposable_domains'];
$this->free_email_provider = $data['free_email_provider'];
$this->creation_date = $data['creation_date'];
$this->expiration_date = $data['expiration_date'];
$this->return_code = $data['return_code'];
$this->disabled = $data['disabled'];
$this->closest_snapshot = $data['closest_snapshot'];
$this->mx_record = $data['mx_record'];
if (!$this->validateDates([$this->creation_date, $this->expiration_date, $this->closest_snapshot])) {
throw new \Exception('Validation failed');
}
}
public function prepareUpdate(): array {
$params = $this->queryParams();
unset($params[':domain']);
$placeholders = array_keys($params);
$updateString = $this->updateStringByPlaceholders($placeholders);
return [$params, $updateString];
}
public function updateEntityInDb(int $entityId, int $apiKey): void {
// total_visit and total_account should remain still
[$params, $updateString] = $this->prepareUpdate();
$params['entity_id'] = $entityId;
$params['key'] = $apiKey;
$query = ("
UPDATE event_domain
SET {$updateString}
WHERE
event_domain.id = :entity_id AND
event_domain.key = :key
");
$model = new \Models\Domain();
$model->execQuery($query, $params);
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Models\Enrichment;
class Email extends \Models\Enrichment\Base {
protected string $email;
protected bool $blockemails;
protected bool $data_breach;
protected int $data_breaches;
protected ?string $earliest_breach;
protected int $profiles;
protected bool $domain_contact_email;
protected string $domain;
protected ?bool $alert_list;
protected bool $checked = true;
public function __construct() {
}
public function init(array $data): void {
$this->email = $data['email'];
$this->blockemails = $data['blockemails'];
$this->data_breach = $data['data_breach'];
$this->data_breaches = $data['data_breaches'];
$this->earliest_breach = $data['earliest_breach'];
$this->profiles = $data['profiles'];
$this->domain_contact_email = $data['domain_contact_email'];
$this->domain = $data['domain'];
$this->alert_list = $data['alert_list'];
if (!$this->validateDates([$this->earliest_breach])) {
throw new \Exception('Validation failed');
}
}
public function prepareUpdate(): array {
$params = $this->queryParams();
unset($params[':email']);
// !
unset($params[':domain']);
// if new alert_list is null -- don't override
if ($params[':alert_list'] === null) {
unset($params[':alert_list']);
}
$placeholders = array_keys($params);
$updateString = $this->updateStringByPlaceholders($placeholders);
return [$params, $updateString];
}
public function updateEntityInDb(int $entityId, int $apiKey): void {
[$params, $updateString] = $this->prepareUpdate();
$params['entity_id'] = $entityId;
$params['key'] = $apiKey;
// other params will stay still
$query = ("
UPDATE event_email
SET {$updateString}
WHERE
event_email.id = :entity_id AND
event_email.key = :key
");
$model = new \Models\Device();
$model->execQuery($query, $params);
}
}

View File

@@ -0,0 +1,155 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Models\Enrichment;
class Ip extends \Models\Enrichment\Base {
protected string $ip; // ipvanyaddress
protected string $country;
protected ?int $asn;
protected ?string $name;
protected bool $hosting;
protected bool $vpn;
protected bool $tor;
protected bool $relay;
protected bool $starlink;
protected ?string $description;
protected bool $blocklist;
protected array $domains_count; // list[str]
protected string $cidr; // ipvanynetwork
protected ?bool $alert_list;
protected bool $checked = true;
protected ?int $isp;
public function __construct() {
// empty
}
public function init(array $data): void {
$this->ip = $data['ip'];
$this->country = $data['country'];
$this->asn = $data['asn'];
$this->name = $data['name'];
$this->hosting = $data['hosting'];
$this->vpn = $data['vpn'];
$this->tor = $data['tor'];
$this->relay = $data['relay'];
$this->starlink = $data['starlink'];
$this->description = $data['description'];
$this->blocklist = $data['blocklist'];
$this->domains_count = $data['domains_count'];
$this->cidr = $data['cidr'];
$this->alert_list = $data['alert_list'];
if (!$this->validateIP($this->ip) || !$this->validateCIDR($this->cidr)) {
throw new \Exception('Validation failed');
}
}
public function prepareUpdate(): array {
$params = $this->queryParams();
unset($params[':ip']);
$params[':domains_count'] = json_encode($params[':domains_count']);
$params[':data_center'] = $params[':hosting'];
unset($params[':hosting']);
// if new alert_list is null -- don't override
if ($params[':alert_list'] === null) {
unset($params[':alert_list']);
}
// set $params[':isp'] later
unset($params[':asn']);
unset($params[':name']);
unset($params[':description']);
$placeholders = array_keys($params);
$updateString = $this->updateStringByPlaceholders($placeholders);
return [$params, $updateString];
}
// TODO: update countries table counters
public function updateEntityInDb(int $entityId, int $apiKey): void {
$ipModel = new \Models\Ip();
$previousIpData = $ipModel->getFullIpInfoById($entityId);
$previousIspId = count($previousIpData) ? $previousIpData['ispid'] : null;
$previousCountryId = count($previousIpData) ? $previousIpData['country_id'] : 0;
// get current isp id
$this->name = $this->asn !== null ? $this->name : 'N/A';
$this->asn = $this->asn !== null ? $this->asn : 64496;
$ispModel = new \Models\Isp();
$newIspId = $ispModel->getIdByAsn($this->asn, $apiKey);
$newIspData = [
'asn' => $this->asn,
'name' => $this->name,
'description' => $this->description,
];
$newIspModel = new \Models\Enrichment\Isp();
$newIspModel->init($newIspData);
// new isp is not in db
if ($newIspId === null) {
$newIspData['lastseen'] = $previousIpData['lastseen'];
$newIspData['created'] = $previousIpData['created'];
$newIspId = $ispModel->insertRecord($newIspData, $apiKey);
} else {
$newIspModel->updateEntityInDb($newIspId, $apiKey);
}
$this->isp = $newIspId;
$countryModel = new \Models\Country();
$newCountryId = $countryModel->getCountryIdByIso($this->country);
$countryRecord = $countryModel->getCountryById($newCountryId, $apiKey);
if (!count($countryRecord)) {
$newCountryData = [
'id' => $newCountryId,
'lastseen' => $previousIpData['lastseen'],
'created' => $previousIpData['created'],
];
$countryModel->insertRecord($newCountryData, $apiKey);
}
// total_visit and total_account should remain still
[$params, $updateString] = $this->prepareUpdate();
$params[':country'] = $newCountryId;
$params[':entity_id'] = $entityId;
$params[':key'] = $apiKey;
$query = ("
UPDATE event_ip
SET {$updateString}
WHERE
event_ip.id = :entity_id AND
event_ip.key = :key
");
$model = new \Models\Ip();
$model->execQuery($query, $params);
// update totals only after event_ip update!
$ispIds = $this->slimIds([$previousIspId, $newIspId]);
$ispModel->updateTotalsByEntityIds($ispIds, $apiKey, true);
$countryIds = $this->slimIds([$previousCountryId, $newCountryId]);
$countryModel->updateTotalsByEntityIds($countryIds, $apiKey, true);
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Models\Enrichment;
class Isp extends \Models\Enrichment\Base {
protected ?int $asn;
protected ?string $name;
protected ?string $description;
public function __construct() {
}
public function init(array $data): void {
$this->asn = $data['asn'];
$this->name = $data['name'];
$this->description = $data['description'];
}
public function prepareUpdate(): array {
$params = $this->queryParams();
unset($params[':asn']);
$placeholders = array_keys($params);
$updateString = $this->updateStringByPlaceholders($placeholders);
return [$params, $updateString];
}
public function updateEntityInDb(int $entityId, int $apiKey): void {
[$params, $updateString] = $this->prepareUpdate();
$params[':entity_id'] = $entityId;
$params[':key'] = $apiKey;
$query = ("
UPDATE event_isp
SET {$updateString}
WHERE
event_isp.id = :entity_id AND
event_isp.key = :key
");
$model = new \Models\Isp();
$model->execQuery($query, $params);
}
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Models\Enrichment;
class LocalhostIp extends \Models\Enrichment\Base {
protected string $ip; // ipvanyaddress
protected int $country = 0;
protected ?int $asn = 0;
protected string $name = 'Local area network';
protected ?string $description = null;
protected bool $checked = true;
protected ?int $isp;
public function __construct() {
// empty
}
public function init(array $data): void {
$this->ip = $data['value'];
if (!$this->validateIP($this->ip) || $data['error'] !== \Utils\Constants::get('ENRICHMENT_IP_IS_BOGON')) {
throw new \Exception('Validation failed');
}
}
public function prepareUpdate(): array {
$params = $this->queryParams();
unset($params[':ip']);
// set $params[':isp'] later
unset($params[':asn']);
unset($params[':name']);
unset($params[':description']);
$placeholders = array_keys($params);
$updateString = $this->updateStringByPlaceholders($placeholders);
return [$params, $updateString];
}
// TODO: update countries table counters
public function updateEntityInDb(int $entityId, int $apiKey): void {
$ipModel = new \Models\Ip();
$previousIpData = $ipModel->getFullIpInfoById($entityId);
$previousIspId = count($previousIpData) ? $previousIpData['ispid'] : null;
$previousCountryId = count($previousIpData) ? $previousIpData['country_id'] : 0;
// get current isp id
$ispModel = new \Models\Isp();
$newIspId = $ispModel->getIdByAsn($this->asn, $apiKey);
$newIspData = [
'asn' => $this->asn,
'name' => $this->name,
'description' => $this->description,
];
$newIspModel = new \Models\Enrichment\Isp();
$newIspModel->init($newIspData);
// new isp is not in db
if ($newIspId === null) {
$newIspData['lastseen'] = $previousIpData['lastseen'];
$newIspId = $ispModel->insertRecord($newIspData, $apiKey);
} else {
$newIspModel->updateEntityInDb($newIspId, $apiKey);
}
$this->isp = $newIspId;
$countryModel = new \Models\Country();
$newCountryId = $countryModel->getCountryIdByIso($this->country);
$countryRecord = $countryModel->getCountryById($newCountryId, $apiKey);
if (!count($countryRecord)) {
$newCountryData = [
'id' => $newCountryId,
'lastseen' => $previousIpData['lastseen'],
];
$countryModel->insertRecord($newCountryData, $apiKey);
}
// total_visit and total_account should remain still
[$params, $updateString] = $this->prepareUpdate();
$params[':country'] = $newCountryId;
$params[':entity_id'] = $entityId;
$params[':key'] = $apiKey;
$query = ("
UPDATE event_ip
SET {$updateString}
WHERE
event_ip.id = :entity_id AND
event_ip.key = :key
");
$model = new \Models\Ip();
$model->execQuery($query, $params);
// update totals only after event_ip update!
$ispIds = $this->slimIds([$previousIspId, $newIspId]);
$ispModel->updateTotalsByEntityIds($ispIds, $apiKey, true);
$countryIds = $this->slimIds([$previousCountryId, $newCountryId]);
$countryModel->updateTotalsByEntityIds($countryIds, $apiKey, true);
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Models\Enrichment;
class PhoneInvalid extends \Models\Enrichment\Base {
protected string $phone_number;
protected bool $invalid;
protected string $validation_errors;
//protected ?bool $alert_list = null;
protected bool $checked = true;
protected int $country_code;
public function __construct() {
}
public function init(array $data): void {
$this->phone_number = $data['phone_number'];
$this->invalid = $data['invalid'];
$this->validation_errors = $data['validation_error'];
$this->country_code = 0;
if (!$this->invalid) {
throw new \Exception('Validation failed');
}
}
public function prepareUpdate(): array {
$params = $this->queryParams();
unset($params[':phone_number']);
$params[':validation_errors'] = json_encode($params[':validation_errors']);
$placeholders = array_keys($params);
$updateString = $this->updateStringByPlaceholders($placeholders);
return [$params, $updateString];
}
public function updateEntityInDb(int $entityId, int $apiKey): void {
[$params, $updateString] = $this->prepareUpdate();
$params['entity_id'] = $entityId;
$params['key'] = $apiKey;
// other params will stay still
$query = ("
UPDATE event_phone
SET {$updateString}
WHERE
event_phone.id = :entity_id AND
event_phone.key = :key
");
$model = new \Models\Phone();
$model->execQuery($query, $params);
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* Tirreno ~ Open source user analytics
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.tirreno.com Tirreno(tm)
*/
namespace Models\Enrichment;
class PhoneValid extends \Models\Enrichment\Base {
protected string $phone_number;
protected int $profiles;
protected ?string $iso_country_code;
protected int $calling_country_code;
protected string $national_format;
protected bool $invalid;
protected ?string $validation_errors;
protected ?string $carrier_name;
protected string $type;
protected ?bool $alert_list;
protected bool $checked = true;
protected int $country_code;
public function __construct() {
}
public function init(array $data): void {
$this->phone_number = $data['phone_number'];
$this->profiles = $data['profiles'];
$this->iso_country_code = $data['iso_country_code'];
$this->calling_country_code = $data['calling_country_code'];
$this->national_format = $data['national_format'];
$this->invalid = $data['invalid'];
$this->validation_errors = $data['validation_error'];
$this->carrier_name = $data['carrier_name'];
$this->type = $data['type'];
$this->alert_list = $data['alert_list'];
if ($this->invalid || $this->validation_errors !== null) {
throw new \Exception('Validation failed');
}
}
public function prepareUpdate(): array {
$params = $this->queryParams();
unset($params[':phone_number']);
$params[':validation_errors'] = json_encode($params[':validation_errors']);
// if new alert_list is null -- don't override
if ($params[':alert_list'] === null) {
unset($params[':alert_list']);
}
$placeholders = array_keys($params);
$updateString = $this->updateStringByPlaceholders($placeholders);
return [$params, $updateString];
}
public function updateEntityInDb(int $entityId, int $apiKey): void {
$this->country_code = 0;
if ($this->iso_country_code !== null) {
$countryModel = new \Models\Country();
$this->country_code = $countryModel->getCountryIdByIso($this->iso_country_code);
}
[$params, $updateString] = $this->prepareUpdate();
$params['entity_id'] = $entityId;
$params['key'] = $apiKey;
$query = ("
UPDATE event_phone
SET {$updateString}
WHERE
event_phone.id = :entity_id AND
event_phone.key = :key
");
$model = new \Models\Phone();
$model->execQuery($query, $params);
}
}