Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| BaseReport | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\DailyReport; |
| 4 | |
| 5 | |
| 6 | |
| 7 | use UserFrosting\UserFrosting; |
| 8 | |
| 9 | class BaseReport extends \Store { |
| 10 | |
| 11 | public $log; |
| 12 | |
| 13 | protected $usersDB; |
| 14 | protected $storeDB; |
| 15 | protected $mainDB; |
| 16 | |
| 17 | public function __construct($typeNum) { |
| 18 | parent::__construct(); |
| 19 | $this->createStore($typeNum); |
| 20 | $this->log = new \KLogger($_ENV['LOG_DIR']."/dailyReports.log", \KLogger::DEBUG); |
| 21 | |
| 22 | // Check if global variables exist |
| 23 | global $usersdb_name; |
| 24 | global $db_name; |
| 25 | |
| 26 | if (!isset($db_name)) { |
| 27 | error_log("ERROR: BaseReport::__construct - Global variable \$db_name not set"); |
| 28 | throw new \Exception("Global database configuration not found"); |
| 29 | } |
| 30 | |
| 31 | if (!isset($usersdb_name)) { |
| 32 | error_log("ERROR: BaseReport::__construct - Global variable \$usersdb_name not set"); |
| 33 | throw new \Exception("Global users database configuration not found"); |
| 34 | } |
| 35 | |
| 36 | // Connect to databases with error handling |
| 37 | $this->mainDB = dbConnectByName($db_name); |
| 38 | if (!$this->mainDB) { |
| 39 | error_log("ERROR: BaseReport::__construct - Failed to connect to main database: $db_name"); |
| 40 | throw new \Exception("Failed to connect to main database"); |
| 41 | } |
| 42 | |
| 43 | $this->usersDB = dbConnectByName($usersdb_name); |
| 44 | if (!$this->usersDB) { |
| 45 | error_log("ERROR: BaseReport::__construct - Failed to connect to users database: $usersdb_name"); |
| 46 | throw new \Exception("Failed to connect to users database"); |
| 47 | } |
| 48 | |
| 49 | $this->storeDB = dbConnectByName($this->getDbName()); |
| 50 | if (!$this->storeDB) { |
| 51 | error_log("ERROR: BaseReport::__construct - Failed to connect to store database: " . $this->getDbName()); |
| 52 | throw new \Exception("Failed to connect to store database"); |
| 53 | } |
| 54 | } |
| 55 | } |