Fix DAO/BAO namespaces and definitions

This commit is contained in:
Jens Schuppe 2024-09-11 12:59:22 +02:00
parent 7cca29b458
commit 64d6b48813
10 changed files with 41 additions and 77 deletions

View file

@ -1,16 +1,10 @@
<?php <?php
namespace Civi\Twingle\Shop\BAO;
use Civi\Api4\PriceField; use Civi\Api4\PriceField;
use Civi\Twingle\Shop\DAO\TwingleProduct as TwingleProductDAO; use Civi\Api4\PriceFieldValue;
use Civi\Twingle\Shop\DAO\TwingleShop as TwingleShopDAO;
use Civi\Twingle\Shop\Exceptions\ProductException; use Civi\Twingle\Shop\Exceptions\ProductException;
use Civi\Twingle\Shop\Exceptions\ShopException; use Civi\Twingle\Shop\Exceptions\ShopException;
use CRM_Core_Exception;
use CRM_Core_Transaction;
use CRM_Twingle_ExtensionUtil as E; use CRM_Twingle_ExtensionUtil as E;
use CRM_Utils_Type;
use function Civi\Twingle\Shop\Utils\convert_int_to_bool; use function Civi\Twingle\Shop\Utils\convert_int_to_bool;
use function Civi\Twingle\Shop\Utils\convert_str_to_date; use function Civi\Twingle\Shop\Utils\convert_str_to_date;
use function Civi\Twingle\Shop\Utils\convert_str_to_int; use function Civi\Twingle\Shop\Utils\convert_str_to_int;
@ -24,7 +18,7 @@ require_once E::path() . '/Civi/Twingle/Shop/Utils/TwingleShopUtils.php';
* TwingleProduct BAO class. * TwingleProduct BAO class.
* This class is used to implement the logic for the TwingleProduct entity. * This class is used to implement the logic for the TwingleProduct entity.
*/ */
class TwingleProduct extends TwingleProductDAO { class CRM_Twingle_BAO_TwingleProduct extends CRM_Twingle_DAO_TwingleProduct {
/** /**
* Name of this product. * Name of this product.
@ -421,14 +415,14 @@ class TwingleProduct extends TwingleProductDAO {
* @param int $external_id * @param int $external_id
* External id of the product (by Twingle) * External id of the product (by Twingle)
* *
* @return TwingleProduct|null * @return CRM_Twingle_BAO_TwingleProduct|null
* TwingleProduct object or NULL if not found * TwingleProduct object or NULL if not found
* *
* @throws \Civi\Twingle\Shop\Exceptions\ProductException * @throws \Civi\Twingle\Shop\Exceptions\ProductException
* @throws \Civi\Core\Exception\DBQueryException * @throws \Civi\Core\Exception\DBQueryException
*/ */
public static function findByExternalId($external_id) { public static function findByExternalId($external_id) {
$dao = TwingleShopDAO::executeQuery("SELECT * FROM civicrm_twingle_product WHERE external_id = %1", $dao = CRM_Twingle_BAO_TwingleShop::executeQuery("SELECT * FROM civicrm_twingle_product WHERE external_id = %1",
[1 => [$external_id, 'String']]); [1 => [$external_id, 'String']]);
if ($dao->fetch()) { if ($dao->fetch()) {
$product = new self(); $product = new self();
@ -456,7 +450,7 @@ class TwingleProduct extends TwingleProductDAO {
// Try to lookup object in database // Try to lookup object in database
try { try {
$dao = TwingleShopDAO::executeQuery("SELECT * FROM civicrm_twingle_product WHERE external_id = %1", $dao = CRM_Twingle_BAO_TwingleShop::executeQuery("SELECT * FROM civicrm_twingle_product WHERE external_id = %1",
[1 => [$this->external_id, 'String']]); [1 => [$this->external_id, 'String']]);
if ($dao->fetch()) { if ($dao->fetch()) {
$this->copyValues(array_merge($dao->toArray(), $this->getAttributes())); $this->copyValues(array_merge($dao->toArray(), $this->getAttributes()));
@ -514,7 +508,7 @@ class TwingleProduct extends TwingleProductDAO {
/** /**
* Delete TwingleProduct along with associated PriceField and PriceFieldValue. * Delete TwingleProduct along with associated PriceField and PriceFieldValue.
* *
* @override \Civi\Twingle\Shop\DAO\TwingleProduct::delete * @override \CRM_Twingle_DAO_TwingleProduct::delete
* @throws \CRM_Core_Exception * @throws \CRM_Core_Exception
* @throws \Civi\Twingle\Shop\Exceptions\ProductException * @throws \Civi\Twingle\Shop\Exceptions\ProductException
*/ */
@ -570,7 +564,7 @@ class TwingleProduct extends TwingleProductDAO {
/** /**
* Compare two products * Compare two products
* *
* @param TwingleProduct $product_to_compare_with * @param CRM_Twingle_BAO_TwingleProduct $product_to_compare_with
* Product from database * Product from database
* *
* @return bool * @return bool
@ -592,7 +586,7 @@ class TwingleProduct extends TwingleProductDAO {
*/ */
public function getFinancialTypeId(): ?int { public function getFinancialTypeId(): ?int {
if (!empty($this->price_field_id)) { if (!empty($this->price_field_id)) {
$price_set = \Civi\Api4\PriceField::get() $price_set = PriceField::get()
->addSelect('financial_type_id') ->addSelect('financial_type_id')
->addWhere('id', '=', $this->price_field_id) ->addWhere('id', '=', $this->price_field_id)
->execute() ->execute()
@ -610,7 +604,7 @@ class TwingleProduct extends TwingleProductDAO {
*/ */
public function getPriceFieldValueId() { public function getPriceFieldValueId() {
if (!empty($this->price_field_id)) { if (!empty($this->price_field_id)) {
$price_field_value = \Civi\Api4\PriceFieldValue::get() $price_field_value = PriceFieldValue::get()
->addSelect('id') ->addSelect('id')
->addWhere('price_field_id', '=', $this->price_field_id) ->addWhere('price_field_id', '=', $this->price_field_id)
->execute() ->execute()

View file

@ -1,15 +1,10 @@
<?php <?php
namespace Civi\Twingle\Shop\BAO;
// phpcs:disable // phpcs:disable
use CRM_Twingle_ExtensionUtil as E; use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Shop\DAO\TwingleShop as TwingleShopDAO;
use Civi\Twingle\Shop\BAO\TwingleProduct as TwingleProductBAO;
use Civi\Twingle\Shop\ApiCall; use Civi\Twingle\Shop\ApiCall;
use Civi\Twingle\Shop\Exceptions\ShopException; use Civi\Twingle\Shop\Exceptions\ShopException;
use Civi\Twingle\Shop\Exceptions\ProductException; use Civi\Twingle\Shop\Exceptions\ProductException;
use Exception;
use function Civi\Twingle\Shop\Utils\filter_attributes; use function Civi\Twingle\Shop\Utils\filter_attributes;
use function Civi\Twingle\Shop\Utils\convert_str_to_int; use function Civi\Twingle\Shop\Utils\convert_str_to_int;
use function Civi\Twingle\Shop\Utils\validate_data_types; use function Civi\Twingle\Shop\Utils\validate_data_types;
@ -17,7 +12,7 @@ use function Civi\Twingle\Shop\Utils\validate_data_types;
require_once E::path() . '/Civi/Twingle/Shop/Utils/TwingleShopUtils.php'; require_once E::path() . '/Civi/Twingle/Shop/Utils/TwingleShopUtils.php';
class TwingleShop extends TwingleShopDAO { class CRM_Twingle_BAO_TwingleShop extends CRM_Twingle_DAO_TwingleShop {
public const ALLOWED_ATTRIBUTES = [ public const ALLOWED_ATTRIBUTES = [
'id' => \CRM_Utils_Type::T_INT, 'id' => \CRM_Utils_Type::T_INT,
@ -64,14 +59,14 @@ class TwingleShop extends TwingleShopDAO {
* @param string $project_identifier * @param string $project_identifier
* Twingle project identifier * Twingle project identifier
* *
* @return TwingleShop * @return CRM_Twingle_BAO_TwingleShop
* *
* @throws ShopException * @throws ShopException
* @throws \Civi\Twingle\Shop\Exceptions\ApiCallError * @throws \Civi\Twingle\Shop\Exceptions\ApiCallError
* @throws \CRM_Core_Exception * @throws \CRM_Core_Exception
*/ */
public static function findByProjectIdentifier(string $project_identifier) { public static function findByProjectIdentifier(string $project_identifier) {
$shop = new TwingleShop(); $shop = new CRM_Twingle_BAO_TwingleShop();
$shop->get('project_identifier', $project_identifier); $shop->get('project_identifier', $project_identifier);
if (!$shop->id) { if (!$shop->id) {
$shop->fetchDataFromTwingle($project_identifier); $shop->fetchDataFromTwingle($project_identifier);
@ -147,7 +142,7 @@ class TwingleShop extends TwingleShopDAO {
// Try to lookup object in database // Try to lookup object in database
try { try {
$dao = TwingleShopDAO::executeQuery("SELECT * FROM civicrm_twingle_shop WHERE project_identifier = %1", $dao = self::executeQuery("SELECT * FROM civicrm_twingle_shop WHERE project_identifier = %1",
[1 => [$this->project_identifier, 'String']]); [1 => [$this->project_identifier, 'String']]);
if ($dao->fetch()) { if ($dao->fetch()) {
$this->load($dao->toArray()); $this->load($dao->toArray());
@ -259,7 +254,7 @@ class TwingleShop extends TwingleShopDAO {
}, []); }, []);
foreach ($products_from_db as $product) { foreach ($products_from_db as $product) {
/* @var TwingleProductBAO $product */ /* @var CRM_Twingle_BAO_TwingleProduct $product */
// Find orphaned products which are in the database but not in Twingle // Find orphaned products which are in the database but not in Twingle
$found = array_key_exists($product->external_id, $products_from_twingle); $found = array_key_exists($product->external_id, $products_from_twingle);
@ -286,8 +281,8 @@ class TwingleShop extends TwingleShopDAO {
foreach ($products_from_twingle as $product_from_twingle) { foreach ($products_from_twingle as $product_from_twingle) {
$found = array_key_exists($product_from_twingle['id'], $products); $found = array_key_exists($product_from_twingle['id'], $products);
if (!$found) { if (!$found) {
$product = new TwingleProduct(); $product = new CRM_Twingle_BAO_TwingleProduct();
$product->load(TwingleProduct::renameTwingleAttrs($product_from_twingle)); $product->load(CRM_Twingle_BAO_TwingleProduct::renameTwingleAttrs($product_from_twingle));
$product->twingle_shop_id = $this->id; $product->twingle_shop_id = $this->id;
$this->products[] = $product; $this->products[] = $product;
} }
@ -305,13 +300,13 @@ class TwingleShop extends TwingleShopDAO {
public function getProducts() { public function getProducts() {
$products = []; $products = [];
$result = TwingleProductBAO::executeQuery( $result = CRM_Twingle_BAO_TwingleProduct::executeQuery(
"SELECT * FROM civicrm_twingle_product WHERE twingle_shop_id = %1", "SELECT * FROM civicrm_twingle_product WHERE twingle_shop_id = %1",
[1 => [$this->id, 'Integer']] [1 => [$this->id, 'Integer']]
); );
while ($result->fetch()) { while ($result->fetch()) {
$product = new TwingleProductBAO(); $product = new CRM_Twingle_BAO_TwingleProduct();
$product->load($result->toArray()); $product->load($result->toArray());
$products[] = $product; $products[] = $product;
} }

View file

@ -1,7 +1,5 @@
<?php <?php
namespace Civi\Twingle\Shop\DAO;
/** /**
* @package CRM * @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing * @copyright CiviCRM LLC https://civicrm.org/licensing
@ -15,7 +13,7 @@ use CRM_Twingle_ExtensionUtil as E;
/** /**
* Database access object for the TwingleProduct entity. * Database access object for the TwingleProduct entity.
*/ */
class TwingleProduct extends \CRM_Core_DAO { class CRM_Twingle_DAO_TwingleProduct extends CRM_Core_DAO {
const EXT = E::LONG_NAME; const EXT = E::LONG_NAME;
const TABLE_ADDED = ''; const TABLE_ADDED = '';
@ -144,7 +142,7 @@ class TwingleProduct extends \CRM_Core_DAO {
'where' => 'civicrm_twingle_product.id', 'where' => 'civicrm_twingle_product.id',
'table_name' => 'civicrm_twingle_product', 'table_name' => 'civicrm_twingle_product',
'entity' => 'TwingleProduct', 'entity' => 'TwingleProduct',
'bao' => 'Civi\Twingle\Shop\DAO\TwingleProduct', 'bao' => 'CRM_Twingle_DAO_TwingleProduct',
'localizable' => 0, 'localizable' => 0,
'html' => [ 'html' => [
'type' => 'Number', 'type' => 'Number',
@ -167,7 +165,7 @@ class TwingleProduct extends \CRM_Core_DAO {
'where' => 'civicrm_twingle_product.external_id', 'where' => 'civicrm_twingle_product.external_id',
'table_name' => 'civicrm_twingle_product', 'table_name' => 'civicrm_twingle_product',
'entity' => 'TwingleProduct', 'entity' => 'TwingleProduct',
'bao' => 'Civi\Twingle\Shop\DAO\TwingleProduct', 'bao' => 'CRM_Twingle_DAO_TwingleProduct',
'localizable' => 0, 'localizable' => 0,
'html' => [ 'html' => [
'type' => 'Number', 'type' => 'Number',
@ -189,7 +187,7 @@ class TwingleProduct extends \CRM_Core_DAO {
'where' => 'civicrm_twingle_product.price_field_id', 'where' => 'civicrm_twingle_product.price_field_id',
'table_name' => 'civicrm_twingle_product', 'table_name' => 'civicrm_twingle_product',
'entity' => 'TwingleProduct', 'entity' => 'TwingleProduct',
'bao' => 'Civi\Twingle\Shop\DAO\TwingleProduct', 'bao' => 'CRM_Twingle_DAO_TwingleProduct',
'localizable' => 0, 'localizable' => 0,
'FKClassName' => 'CRM_Contact_DAO_Contact', 'FKClassName' => 'CRM_Contact_DAO_Contact',
'add' => NULL, 'add' => NULL,
@ -208,9 +206,9 @@ class TwingleProduct extends \CRM_Core_DAO {
'where' => 'civicrm_twingle_product.twingle_shop_id', 'where' => 'civicrm_twingle_product.twingle_shop_id',
'table_name' => 'civicrm_twingle_product', 'table_name' => 'civicrm_twingle_product',
'entity' => 'TwingleProduct', 'entity' => 'TwingleProduct',
'bao' => 'Civi\Twingle\Shop\DAO\TwingleProduct', 'bao' => 'CRM_Twingle_DAO_TwingleProduct',
'localizable' => 0, 'localizable' => 0,
'FKClassName' => 'Civi\Twingle\Shop\DAO\TwingleShop', 'FKClassName' => 'CRM_Twingle_DAO_TwingleShop',
'add' => NULL, 'add' => NULL,
], ],
'created_at' => [ 'created_at' => [
@ -228,7 +226,7 @@ class TwingleProduct extends \CRM_Core_DAO {
'where' => 'civicrm_twingle_product.created_at', 'where' => 'civicrm_twingle_product.created_at',
'table_name' => 'civicrm_twingle_product', 'table_name' => 'civicrm_twingle_product',
'entity' => 'TwingleProduct', 'entity' => 'TwingleProduct',
'bao' => 'Civi\Twingle\Shop\DAO\TwingleProduct', 'bao' => 'CRM_Twingle_DAO_TwingleProduct',
'localizable' => 0, 'localizable' => 0,
'add' => NULL, 'add' => NULL,
], ],
@ -247,7 +245,7 @@ class TwingleProduct extends \CRM_Core_DAO {
'where' => 'civicrm_twingle_product.updated_at', 'where' => 'civicrm_twingle_product.updated_at',
'table_name' => 'civicrm_twingle_product', 'table_name' => 'civicrm_twingle_product',
'entity' => 'TwingleProduct', 'entity' => 'TwingleProduct',
'bao' => 'Civi\Twingle\Shop\DAO\TwingleProduct', 'bao' => 'CRM_Twingle_DAO_TwingleProduct',
'localizable' => 0, 'localizable' => 0,
'add' => NULL, 'add' => NULL,
], ],

View file

@ -1,7 +1,5 @@
<?php <?php
namespace Civi\Twingle\Shop\DAO;
/** /**
* @package CRM * @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing * @copyright CiviCRM LLC https://civicrm.org/licensing
@ -15,7 +13,7 @@ use CRM_Twingle_ExtensionUtil as E;
/** /**
* Database access object for the TwingleShop entity. * Database access object for the TwingleShop entity.
*/ */
class TwingleShop extends \CRM_Core_DAO { class CRM_Twingle_DAO_TwingleShop extends CRM_Core_DAO {
const EXT = E::LONG_NAME; const EXT = E::LONG_NAME;
const TABLE_ADDED = ''; const TABLE_ADDED = '';
@ -134,7 +132,7 @@ class TwingleShop extends \CRM_Core_DAO {
'where' => 'civicrm_twingle_shop.id', 'where' => 'civicrm_twingle_shop.id',
'table_name' => 'civicrm_twingle_shop', 'table_name' => 'civicrm_twingle_shop',
'entity' => 'TwingleShop', 'entity' => 'TwingleShop',
'bao' => 'Civi\Twingle\Shop\DAO\TwingleShop', 'bao' => 'CRM_Twingle_DAO_TwingleShop',
'localizable' => 0, 'localizable' => 0,
'html' => [ 'html' => [
'type' => 'Number', 'type' => 'Number',
@ -159,7 +157,7 @@ class TwingleShop extends \CRM_Core_DAO {
'where' => 'civicrm_twingle_shop.project_identifier', 'where' => 'civicrm_twingle_shop.project_identifier',
'table_name' => 'civicrm_twingle_shop', 'table_name' => 'civicrm_twingle_shop',
'entity' => 'TwingleShop', 'entity' => 'TwingleShop',
'bao' => 'Civi\Twingle\Shop\DAO\TwingleShop', 'bao' => 'CRM_Twingle_DAO_TwingleShop',
'localizable' => 0, 'localizable' => 0,
'html' => [ 'html' => [
'type' => 'Text', 'type' => 'Text',
@ -181,7 +179,7 @@ class TwingleShop extends \CRM_Core_DAO {
'where' => 'civicrm_twingle_shop.numerical_project_id', 'where' => 'civicrm_twingle_shop.numerical_project_id',
'table_name' => 'civicrm_twingle_shop', 'table_name' => 'civicrm_twingle_shop',
'entity' => 'TwingleShop', 'entity' => 'TwingleShop',
'bao' => 'Civi\Twingle\Shop\DAO\TwingleShop', 'bao' => 'CRM_Twingle_DAO_TwingleShop',
'localizable' => 0, 'localizable' => 0,
'html' => [ 'html' => [
'type' => 'Number', 'type' => 'Number',
@ -202,7 +200,7 @@ class TwingleShop extends \CRM_Core_DAO {
'where' => 'civicrm_twingle_shop.price_set_id', 'where' => 'civicrm_twingle_shop.price_set_id',
'table_name' => 'civicrm_twingle_shop', 'table_name' => 'civicrm_twingle_shop',
'entity' => 'TwingleShop', 'entity' => 'TwingleShop',
'bao' => 'Civi\Twingle\Shop\DAO\TwingleShop', 'bao' => 'CRM_Twingle_DAO_TwingleShop',
'localizable' => 0, 'localizable' => 0,
'FKClassName' => 'CRM_Price_DAO_PriceSet', 'FKClassName' => 'CRM_Price_DAO_PriceSet',
'add' => NULL, 'add' => NULL,

View file

@ -20,7 +20,11 @@
<compatibility> <compatibility>
<ver>5.58</ver> <ver>5.58</ver>
</compatibility> </compatibility>
<comments/> <comments></comments>
<classloader>
<psr4 prefix="Civi\" path="Civi"/>
<psr0 prefix="CRM_" path="."/>
</classloader>
<requires> <requires>
<ext>de.systopia.xcm</ext> <ext>de.systopia.xcm</ext>
</requires> </requires>
@ -32,10 +36,7 @@
<mixin>menu-xml@1.0.0</mixin> <mixin>menu-xml@1.0.0</mixin>
<mixin>mgd-php@1.0.0</mixin> <mixin>mgd-php@1.0.0</mixin>
<mixin>smarty-v2@1.0.1</mixin> <mixin>smarty-v2@1.0.1</mixin>
<mixin>entity-types-php@1.0.0</mixin>
</mixins> </mixins>
<classloader>
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<upgrader>CRM_Twingle_Upgrader</upgrader> <upgrader>CRM_Twingle_Upgrader</upgrader>
</extension> </extension>

View file

@ -198,25 +198,3 @@ function _twingle_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) {
} }
} }
} }
/**
* (Delegated) Implements hook_civicrm_entityTypes().
*
* Find any *.entityType.php files, merge their content, and return.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
*/
function _twingle_civix_civicrm_entityTypes(&$entityTypes) {
$entityTypes = array_merge($entityTypes, [
'Civi\Twingle\Shop\DAO\TwingleProduct' => [
'name' => 'TwingleProduct',
'class' => 'Civi\Twingle\Shop\DAO\TwingleProduct',
'table' => 'civicrm_twingle_product',
],
'Civi\Twingle\Shop\DAO\TwingleShop' => [
'name' => 'TwingleShop',
'class' => 'Civi\Twingle\Shop\DAO\TwingleShop',
'table' => 'civicrm_twingle_shop',
],
]);
}

View file

@ -4,7 +4,7 @@
return [ return [
[ [
'name' => 'TwingleProduct', 'name' => 'TwingleProduct',
'class' => 'Civi\Twingle\Shop\DAO\TwingleProduct', 'class' => 'CRM_Twingle_DAO_TwingleProduct',
'table' => 'civicrm_twingle_product', 'table' => 'civicrm_twingle_product',
], ],
]; ];

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1" ?> <?xml version="1.0" encoding="iso-8859-1" ?>
<table> <table>
<base>CRM/Twingle/Shop</base> <base>CRM/Twingle</base>
<class>TwingleProduct</class> <class>TwingleProduct</class>
<name>civicrm_twingle_product</name> <name>civicrm_twingle_product</name>
<comment>This table contains the Twingle Product data.</comment> <comment>This table contains the Twingle Product data.</comment>

View file

@ -4,7 +4,7 @@
return [ return [
[ [
'name' => 'TwingleShop', 'name' => 'TwingleShop',
'class' => 'Civi\Twingle\Shop\DAO\TwingleShop', 'class' => 'CRM_Twingle_DAO_TwingleShop',
'table' => 'civicrm_twingle_shop', 'table' => 'civicrm_twingle_shop',
], ],
]; ];

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1" ?> <?xml version="1.0" encoding="iso-8859-1" ?>
<table> <table>
<base>CRM/Twingle/Shop</base> <base>CRM/Twingle</base>
<class>TwingleShop</class> <class>TwingleShop</class>
<name>civicrm_twingle_shop</name> <name>civicrm_twingle_shop</name>
<comment>This table contains the Twingle Shop data. Each Twingle Shop is linked to a corresponding Price Set.</comment> <comment>This table contains the Twingle Shop data. Each Twingle Shop is linked to a corresponding Price Set.</comment>