1
|
|
|
<?php namespace Comodojo\Extender; |
2
|
|
|
|
3
|
|
|
use Comodojo\Exception\DatabaseException; |
4
|
|
|
use Comodojo\Database\EnhancedDatabase; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Framework wide checks |
8
|
|
|
* |
9
|
|
|
* @package Comodojo extender |
10
|
|
|
* @author Marco Giovinazzi <[email protected]> |
11
|
|
|
* @license GPL-3.0+ |
12
|
|
|
* |
13
|
|
|
* LICENSE: |
14
|
|
|
* |
15
|
|
|
* This program is free software: you can redistribute it and/or modify |
16
|
|
|
* it under the terms of the GNU Affero General Public License as |
17
|
|
|
* published by the Free Software Foundation, either version 3 of the |
18
|
|
|
* License, or (at your option) any later version. |
19
|
|
|
* |
20
|
|
|
* This program is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU Affero General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* You should have received a copy of the GNU Affero General Public License |
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
class Checks { |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Check for required configuration constants |
33
|
|
|
* |
34
|
|
|
* @return mixed Boolean true in case of success, string with error message otherwise |
35
|
|
|
*/ |
36
|
12 |
|
final public static function constants() { |
37
|
|
|
|
38
|
12 |
|
if ( !defined("EXTENDER_IDLE_TIME") ) return "Idle time not configured correctly. \n\n Please check your extender configuration and define constant: EXTENDER_IDLE_TIME."; |
39
|
12 |
|
if ( !defined("EXTENDER_DATABASE_MODEL") ) return "Invalid database model. \n\n Please check your extender configuration and define constant: EXTENDER_DATABASE_MODEL."; |
40
|
12 |
|
if ( !defined("EXTENDER_DATABASE_HOST") ) return "Unknown database host. \n\n Please check your extender configuration and define constant: EXTENDER_DATABASE_HOST."; |
41
|
12 |
|
if ( !defined("EXTENDER_DATABASE_PORT") ) return "Invalid database port. \n\n Please check your extender configuration and define constant: EXTENDER_DATABASE_PORT."; |
42
|
12 |
|
if ( !defined("EXTENDER_DATABASE_NAME") ) return "Invalid database name. \n\n Please check your extender configuration and define constant: EXTENDER_DATABASE_NAME."; |
43
|
12 |
|
if ( !defined("EXTENDER_DATABASE_USER") ) return "Invalid database user. \n\n Please check your extender configuration and define constant: EXTENDER_DATABASE_USER."; |
44
|
12 |
|
if ( !defined("EXTENDER_DATABASE_PASS") ) return "Invalid database password. \n\n Please check your extender configuration and define constant: EXTENDER_DATABASE_PASS."; |
45
|
12 |
|
if ( !defined("EXTENDER_DATABASE_PREFIX") ) return "Invalid database table prefix. \n\n Please check your extender configuration and define constant: EXTENDER_DATABASE_PREFIX."; |
46
|
12 |
|
if ( !defined("EXTENDER_DATABASE_TABLE_JOBS") ) return "Invalid database jobs' table. \n\n Please check your extender configuration and define constant: EXTENDER_DATABASE_TABLE_JOBS."; |
47
|
12 |
|
if ( !defined("EXTENDER_DATABASE_TABLE_WORKLOGS") ) return "Invalid database worklogs' table. \n\n Please check your extender configuration and define constant: EXTENDER_DATABASE_TABLE_WORKLOGS."; |
48
|
12 |
|
if ( !defined("EXTENDER_CACHE_FOLDER") ) return "Invalid cache folder. \n\n Please check your extender configuration and define constant: EXTENDER_CACHE_FOLDER."; |
49
|
|
|
|
50
|
12 |
|
return true; |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Check if script is running from command line |
56
|
|
|
* |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
12 |
|
final public static function cli() { |
60
|
|
|
|
61
|
12 |
|
return php_sapi_name() === 'cli'; |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Check if php interpreter supports pcntl_fork (required in multithread mode) |
67
|
|
|
* |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
12 |
|
final public static function multithread() { |
71
|
|
|
|
72
|
12 |
|
return function_exists("pcntl_fork"); |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Check if php interpreter supports pcntl signal handlers |
78
|
|
|
* |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
12 |
|
final public static function signals() { |
82
|
|
|
|
83
|
12 |
|
return function_exists("pcntl_signal"); |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Check if database is available and initialized correctly |
89
|
|
|
* |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
12 |
|
final public static function database() { |
93
|
|
|
|
94
|
|
|
try { |
95
|
|
|
|
96
|
12 |
|
$db = new EnhancedDatabase( |
97
|
12 |
|
EXTENDER_DATABASE_MODEL, |
98
|
12 |
|
EXTENDER_DATABASE_HOST, |
99
|
12 |
|
EXTENDER_DATABASE_PORT, |
100
|
12 |
|
EXTENDER_DATABASE_NAME, |
101
|
12 |
|
EXTENDER_DATABASE_USER, |
102
|
|
|
EXTENDER_DATABASE_PASS |
103
|
12 |
|
); |
104
|
|
|
|
105
|
12 |
|
$db->tablePrefix(EXTENDER_DATABASE_PREFIX)->table(EXTENDER_DATABASE_TABLE_JOBS)->keys("*")->get(1); |
106
|
|
|
|
107
|
12 |
|
} catch (DatabaseException $de) { |
108
|
|
|
|
109
|
|
|
unset($db); |
110
|
|
|
|
111
|
|
|
return false; |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
12 |
|
unset($db); |
116
|
|
|
|
117
|
12 |
|
return true; |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|