Fix BAO class namespace issues

This commit is contained in:
Jens Schuppe 2024-10-09 12:39:57 +02:00
parent 82952a0162
commit c7c766d926
10 changed files with 16 additions and 22 deletions

View file

@ -294,7 +294,7 @@ class CRM_Twingle_BAO_TwingleShop extends CRM_Twingle_DAO_TwingleShop {
/** /**
* Get associated products. * Get associated products.
* *
* @return array[Civi\Twingle\Shop\BAO\TwingleProduct] * @return list<CRM_Twingle_BAO_TwingleProduct>
* @throws \Civi\Core\Exception\DBQueryException * @throws \Civi\Core\Exception\DBQueryException
* @throws \Civi\Twingle\Shop\Exceptions\ProductException * @throws \Civi\Twingle\Shop\Exceptions\ProductException
*/ */

View file

@ -18,7 +18,6 @@ declare(strict_types = 1);
use CRM_Twingle_ExtensionUtil as E; use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Exceptions\BaseException; use Civi\Twingle\Exceptions\BaseException;
use Civi\Twingle\Shop\Exceptions\LineItemException; use Civi\Twingle\Shop\Exceptions\LineItemException;
use Civi\Twingle\Shop\BAO\TwingleProduct;
class CRM_Twingle_Submission { class CRM_Twingle_Submission {
@ -503,7 +502,7 @@ class CRM_Twingle_Submission {
// Try to find the TwingleProduct with its corresponding PriceField // Try to find the TwingleProduct with its corresponding PriceField
// for this product // for this product
try { try {
$price_field = TwingleProduct::findByExternalId($product['id']); $price_field = CRM_Twingle_BAO_TwingleProduct::findByExternalId($product['id']);
} }
catch (Exception $e) { catch (Exception $e) {
Civi::log()->error(E::LONG_NAME . Civi::log()->error(E::LONG_NAME .

View file

@ -2,7 +2,6 @@
use Civi\Twingle\Shop\Exceptions\ProductException; use Civi\Twingle\Shop\Exceptions\ProductException;
use CRM_Twingle_ExtensionUtil as E; use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Shop\BAO\TwingleProduct;
/** /**
* TwingleProduct.Create API specification (optional) * TwingleProduct.Create API specification (optional)
@ -121,7 +120,7 @@ function civicrm_api3_twingle_product_Create($params): array {
try { try {
// Create TwingleProduct and load params // Create TwingleProduct and load params
$product = new TwingleProduct(); $product = new CRM_Twingle_BAO_TwingleProduct();
$product->load($params); $product->load($params);
// Save TwingleProduct // Save TwingleProduct

View file

@ -1,7 +1,6 @@
<?php <?php
use CRM_Twingle_ExtensionUtil as E; use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Shop\BAO\TwingleProduct;
/** /**
* TwingleProduct.Delete API specification (optional) * TwingleProduct.Delete API specification (optional)
@ -56,7 +55,7 @@ function civicrm_api3_twingle_product_Delete($params) {
} }
// Get TwingleProduct object // Get TwingleProduct object
$product = TwingleProduct::findById($product_data['id']); $product = CRM_Twingle_BAO_TwingleProduct::findById($product_data['id']);
// Delete TwingleProduct and associated PriceField and PriceFieldValue // Delete TwingleProduct and associated PriceField and PriceFieldValue
$result = $product->delete(); $result = $product->delete();

View file

@ -1,7 +1,6 @@
<?php <?php
use CRM_Twingle_ExtensionUtil as E; use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Shop\BAO\TwingleProduct;
/** /**
* TwingleProduct.Get API specification (optional) * TwingleProduct.Get API specification (optional)
@ -87,7 +86,7 @@ function civicrm_api3_twingle_product_Get($params) {
$altered_params = []; $altered_params = [];
// Specify product fields to define table prefix // Specify product fields to define table prefix
$productFields = array_keys(TwingleProduct::fields()); $productFields = array_keys(CRM_Twingle_BAO_TwingleProduct::fields());
// Alter params (prefix with table name) // Alter params (prefix with table name)
foreach ($possible_params as $param) { foreach ($possible_params as $param) {
@ -118,7 +117,7 @@ function civicrm_api3_twingle_product_Get($params) {
// Execute query // Execute query
try { try {
$dao = TwingleProduct::executeQuery($query, $query_params); $dao = CRM_Twingle_BAO_TwingleProduct::executeQuery($query, $query_params);
} }
catch (Exception $e) { catch (Exception $e) {
return civicrm_api3_create_error($e->getMessage(), [ return civicrm_api3_create_error($e->getMessage(), [

View file

@ -1,6 +1,5 @@
<?php <?php
use CRM_Twingle_ExtensionUtil as E; use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Shop\BAO\TwingleShop;
use Civi\Twingle\Shop\Exceptions\ShopException; use Civi\Twingle\Shop\Exceptions\ShopException;
/** /**
@ -62,7 +61,7 @@ function civicrm_api3_twingle_shop_Create($params) {
try { try {
// Create TwingleShop and load params // Create TwingleShop and load params
$shop = new TwingleShop(); $shop = new CRM_Twingle_BAO_TwingleShop();
$shop->load($params); $shop->load($params);
// Save TwingleShop // Save TwingleShop

View file

@ -1,6 +1,6 @@
<?php <?php
use CRM_Twingle_ExtensionUtil as E; use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Shop\BAO\TwingleShop;
/** /**
* TwingleShop.Delete API specification (optional) * TwingleShop.Delete API specification (optional)
@ -56,10 +56,10 @@ function civicrm_api3_twingle_shop_Delete($params) {
} }
// Get TwingleShop object // Get TwingleShop object
$shop = TwingleShop::findById($shop_data['id']); $shop = CRM_Twingle_BAO_TwingleShop::findById($shop_data['id']);
// Delete TwingleShop // Delete TwingleShop
/* @var \Civi\Twingle\Shop\BAO\TwingleShop $shop */ /** @var \CRM_Twingle_BAO_TwingleShop $shop */
$result = $shop->deleteByConstraint(); $result = $shop->deleteByConstraint();
if ($result) { if ($result) {
return civicrm_api3_create_success(1, $params, 'TwingleShop', 'Delete'); return civicrm_api3_create_success(1, $params, 'TwingleShop', 'Delete');

View file

@ -1,7 +1,6 @@
<?php <?php
use CRM_Twingle_ExtensionUtil as E; use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Shop\BAO\TwingleShop;
use Civi\Twingle\Shop\Exceptions\ApiCallError; use Civi\Twingle\Shop\Exceptions\ApiCallError;
use Civi\Twingle\Shop\Exceptions\ProductException; use Civi\Twingle\Shop\Exceptions\ProductException;
use Civi\Twingle\Shop\Exceptions\ShopException; use Civi\Twingle\Shop\Exceptions\ShopException;
@ -55,7 +54,7 @@ function civicrm_api3_twingle_shop_Fetch($params) {
// Get products for all projects of type 'shop' // Get products for all projects of type 'shop'
foreach ($projectIds as $projectId) { foreach ($projectIds as $projectId) {
try { try {
$shop = TwingleShop::findByProjectIdentifier($projectId); $shop = CRM_Twingle_BAO_TwingleShop::findByProjectIdentifier($projectId);
$products = $shop->fetchProducts(); $products = $shop->fetchProducts();
$returnValues[$projectId] = []; $returnValues[$projectId] = [];
$returnValues[$projectId] += $shop->getAttributes(); $returnValues[$projectId] += $shop->getAttributes();
@ -63,7 +62,7 @@ function civicrm_api3_twingle_shop_Fetch($params) {
return $product->getAttributes(); return $product->getAttributes();
}, $products); }, $products);
} }
catch (ShopException|ApiCallError|ProductException $e) { catch (ShopException | ApiCallError | ProductException $e) {
// If this project identifier doesn't belong to a project of type // If this project identifier doesn't belong to a project of type
// 'shop', just skip it // 'shop', just skip it
if ($e->getErrorCode() == ShopException::ERROR_CODE_NOT_A_SHOP) { if ($e->getErrorCode() == ShopException::ERROR_CODE_NOT_A_SHOP) {

View file

@ -1,6 +1,6 @@
<?php <?php
use CRM_Twingle_ExtensionUtil as E; use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Shop\BAO\TwingleShop;
/** /**
* TwingleShop.Get API specification (optional) * TwingleShop.Get API specification (optional)
@ -92,7 +92,7 @@ function civicrm_api3_twingle_shop_Get($params) {
// Execute query // Execute query
try { try {
$dao = TwingleShop::executeQuery($query, $query_params); $dao = CRM_Twingle_BAO_TwingleShop::executeQuery($query, $query_params);
} }
catch (\Exception $e) { catch (\Exception $e) {
return civicrm_api3_create_error($e->getMessage(), [ return civicrm_api3_create_error($e->getMessage(), [

View file

@ -17,7 +17,7 @@ function twingle_civicrm_pre($op, $objectName, $id, &$params) {
// Create/delete PriceField and PriceFieldValue for TwingleProduct // Create/delete PriceField and PriceFieldValue for TwingleProduct
elseif ($objectName == 'TwingleProduct') { elseif ($objectName == 'TwingleProduct') {
$twingle_product = new \Civi\Twingle\Shop\BAO\TwingleProduct(); $twingle_product = new CRM_Twingle_BAO_TwingleProduct();
$twingle_product->load($params); $twingle_product->load($params);
if ($op == 'create' || $op == 'edit') { if ($op == 'create' || $op == 'edit') {
$twingle_product->createPriceField(); $twingle_product->createPriceField();
@ -30,7 +30,7 @@ function twingle_civicrm_pre($op, $objectName, $id, &$params) {
// Create PriceSet for TwingleShop // Create PriceSet for TwingleShop
elseif ($objectName == 'TwingleShop' && ($op == 'create' || $op == 'edit')) { elseif ($objectName == 'TwingleShop' && ($op == 'create' || $op == 'edit')) {
$twingle_shop = new \Civi\Twingle\Shop\BAO\TwingleShop(); $twingle_shop = new CRM_Twingle_BAO_TwingleShop();
$twingle_shop->load($params); $twingle_shop->load($params);
$twingle_shop->createPriceSet(); $twingle_shop->createPriceSet();
$params = $twingle_shop->getAttributes(); $params = $twingle_shop->getAttributes();