Skip to content

Commit be1fe9c

Browse files
committed
Code style updates
1 parent 68c988e commit be1fe9c

22 files changed

+1171
-1164
lines changed

Diff for: api.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,9 @@
403403
$result['performance']=PerformanceReport(1);
404404
}
405405

406-
header("Content-type:application/json");
406+
if (!headers_sent()) {
407+
header("Content-type:application/json");
408+
}
407409
echo json_encode($result);
408410

409411
function apiShutdown() {

Diff for: cycle.php

+45-41
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
//если есть "поломанные" таблицы, попытаться их "вылечить"
4646
echo "CHECK/REPAIR TABLES\n";
47-
$tables = SQLSelect("select TABLE_NAME Tbl from information_schema.tables where TABLE_SCHEMA='".DB_NAME."' AND ENGINE !='MEMORY';");
47+
$tables = SQLSelect("select TABLE_NAME Tbl from information_schema.tables where TABLE_SCHEMA='" . DB_NAME . "' AND ENGINE !='MEMORY';");
4848
$total = count($tables);
4949
$checked = 0;
5050
$broken = 0;
@@ -64,34 +64,34 @@
6464
SQLExec("REPAIR TABLE " . $table . ";");
6565
sleep(10);
6666
$result = SQLSelectOne("CHECK TABLE " . $table . ";");
67-
if ($result['Msg_text'] == 'OK') {
68-
echo "OK\n";
69-
$repaired = $repaired + 1;
70-
} else {
71-
echo "try to repair extended...";
72-
SQLExec("REPAIR TABLE " . $table . " EXTENDED;");
73-
sleep(10);
74-
$result = SQLSelectOne("CHECK TABLE " . $table . ";");
7567
if ($result['Msg_text'] == 'OK') {
7668
echo "OK\n";
77-
$repaired = $repaired + 1;
69+
$repaired = $repaired + 1;
7870
} else {
79-
echo "try to repair use_frm...";
80-
SQLExec("REPAIR TABLE " . $table . " USE_FRM;");
71+
echo "try to repair extended...";
72+
SQLExec("REPAIR TABLE " . $table . " EXTENDED;");
8173
sleep(10);
74+
$result = SQLSelectOne("CHECK TABLE " . $table . ";");
75+
if ($result['Msg_text'] == 'OK') {
76+
echo "OK\n";
77+
$repaired = $repaired + 1;
78+
} else {
79+
echo "try to repair use_frm...";
80+
SQLExec("REPAIR TABLE " . $table . " USE_FRM;");
81+
sleep(10);
8282
$result = SQLSelectOne("CHECK TABLE " . $table . ";");
83-
if ($result['Msg_text'] == 'OK') {
84-
echo "OK\n";
83+
if ($result['Msg_text'] == 'OK') {
84+
echo "OK\n";
8585
$repaired = $repaired + 1;
86-
} else {
87-
echo "NO RESULT(...try restore from backup\n";
86+
} else {
87+
echo "NO RESULT(...try restore from backup\n";
8888
$fatal = $fatal + 1;
89-
}
89+
}
90+
}
9091
}
91-
}
9292
}
9393
}
94-
echo "CHECK/REPAIR TABLES RESULT -> Total: ".$total.", checked Ok: ".$checked.", broken: ".$broken.", repaired: ".$repaired.", FATAL Errors : ".$fatal;
94+
echo "CHECK/REPAIR TABLES RESULT -> Total: " . $total . ", checked Ok: " . $checked . ", broken: " . $broken . ", repaired: " . $repaired . ", FATAL Errors : " . $fatal;
9595
echo "\n";
9696

9797
// создаем табличку cyclesRun, если её нет
@@ -185,7 +185,7 @@
185185
$mysql_path = (substr(php_uname(), 0, 7) == "Windows") ? SERVER_ROOT . "/server/mysql/bin/mysql" : 'mysql';
186186
$mysqlParam = " -h " . DB_HOST;
187187
$mysqlParam .= " -u " . DB_USER;
188-
if (DB_PASSWORD != '') $mysqlParam .= " -p'" . DB_PASSWORD."'";
188+
if (DB_PASSWORD != '') $mysqlParam .= " -p'" . DB_PASSWORD . "'";
189189
$mysqlParam .= " " . DB_NAME . " <" . $db_filename;
190190
exec($mysql_path . $mysqlParam);
191191

@@ -195,7 +195,7 @@
195195
$mysql_path = (substr(php_uname(), 0, 7) == "Windows") ? SERVER_ROOT . "/server/mysql/bin/mysql" : 'mysql';
196196
$mysqlParam = " -h " . DB_HOST;
197197
$mysqlParam .= " -u " . DB_USER;
198-
if (DB_PASSWORD != '') $mysqlParam .= " -p'" . DB_PASSWORD."'";
198+
if (DB_PASSWORD != '') $mysqlParam .= " -p'" . DB_PASSWORD . "'";
199199
$mysqlParam .= " " . DB_NAME . " <" . $db_history_filename;
200200
exec($mysql_path . $mysqlParam);
201201
}
@@ -210,12 +210,16 @@
210210
$source = ROOT . 'modules';
211211
if ($dir = @opendir($source)) {
212212
while (($file = readdir($dir)) !== false) {
213-
if (Is_Dir($source . "/" . $file) && ($file != '.') && ($file != '..')) {
214-
@unlink(ROOT . "cms/modules_installed/" . $file . ".installed");
213+
$installed_file = ROOT . "cms/modules_installed/" . $file . ".installed";
214+
if (Is_Dir($source . "/" . $file) && ($file != '.') && ($file != '..') && is_file($installed_file)) {
215+
unlink($installed_file);
215216
}
216217
}
217218
}
218-
@unlink(ROOT . "cms/modules_installed/control_modules.installed");
219+
220+
if (is_file(ROOT . "cms/modules_installed/control_modules.installed")) {
221+
unlink(ROOT . "cms/modules_installed/control_modules.installed");
222+
}
219223

220224
// continue startup
221225
include_once(DIR_MODULES . "control_modules/control_modules.class.php");
@@ -269,26 +273,26 @@
269273

270274
$total = count($cycles_records);
271275
for ($i = 0; $i < $total; $i++) {
272-
DebMes("Removing property ThisComputer.$property (object ".$thisCompObject->id.")",'threads');
273-
echo "Removing ThisComputer.$property (object " . $thisCompObject->id . ")";
274276
$property = $cycles_records[$i]['TITLE'];
277+
echo "Removing ThisComputer.$property (object " . $thisCompObject->id . ")";
278+
DebMes("Removing property ThisComputer.$property (object " . $thisCompObject->id . ")", 'threads');
275279
$property_id = $thisCompObject->getPropertyByName($property, $thisCompObject->class_id, $thisCompObject->id);
276280
//DebMes("Property id: $property_id",'threads');
277281
if ($property_id) {
278282
$sqlQuery = "SELECT ID FROM pvalues WHERE PROPERTY_ID = " . (int)$property_id;
279283
$pvalue = SQLSelectOne($sqlQuery);
280284
if ($pvalue['ID']) {
281-
DebMes("Deleting Pvalue: ".$pvalue['ID'],'threads');
285+
DebMes("Deleting Pvalue: " . $pvalue['ID'], 'threads');
282286
SQLExec("DELETE FROM phistory WHERE VALUE_ID=" . $pvalue['ID']);
283287
SQLExec("DELETE FROM pvalues WHERE ID=" . $pvalue['ID']);
284288
} else {
285-
DebMes("NO Pvalue for ".$property_id,'threads');
289+
DebMes("NO Pvalue for " . $property_id, 'threads');
286290
}
287291
SQLExec("DELETE FROM properties WHERE ID=" . $property_id);
288-
DebMes("REMOVED $property_id",'threads');
292+
DebMes("REMOVED $property_id", 'threads');
289293
echo " REMOVED $property_id\n";
290294
} else {
291-
DebMes("No property record found for $property",'threads');
295+
DebMes("No property record found for $property", 'threads');
292296
echo " FAILED\n";
293297
}
294298
}
@@ -388,16 +392,16 @@
388392
if ((time() - $last_cycles_control_check) >= 5 || !empty($result)) {
389393

390394
$last_cycles_control_check = time();
391-
$cyclesControls=$cyclesTimestamps=array();
392-
$tmpcyclesTimestamps=SQLSelect("SELECT * FROM cached_cycles;");
395+
$cyclesControls = $cyclesTimestamps = array();
396+
$tmpcyclesTimestamps = SQLSelect("SELECT * FROM cached_cycles;");
393397

394398
$total = count($tmpcyclesTimestamps);
395399
foreach ($tmpcyclesTimestamps as $k => $v) {
396-
if (strpos($v['TITLE'],'Run') !== FALSE) {
397-
$cyclesTimestamps[$v['TITLE']] = $v['VALUE'];
398-
} else if (strpos($v['TITLE'],'Control') !== FALSE) {
399-
$cyclesControls[$v['TITLE']] = $v['VALUE'];
400-
}
400+
if (strpos($v['TITLE'], 'Run') !== FALSE) {
401+
$cyclesTimestamps[$v['TITLE']] = $v['VALUE'];
402+
} else if (strpos($v['TITLE'], 'Control') !== FALSE) {
403+
$cyclesControls[$v['TITLE']] = $v['VALUE'];
404+
}
401405
}
402406

403407
$seen = array();
@@ -409,7 +413,7 @@
409413
continue;
410414
}
411415
$seen[$title] = 1;
412-
$control='';
416+
$control = '';
413417

414418
if (isset($cyclesControls[$title . 'Control'])) $control = $cyclesControls[$title . 'Control'];
415419
if ($control != '') {
@@ -436,10 +440,10 @@
436440
DebMes("Adding $title to auto-recovery list", 'threads');
437441
$auto_restarts[] = $title;
438442
}
439-
$cycle_updated_timestamp=$cyclesTimestamps[$title.'Run'];
443+
$cycle_updated_timestamp = $cyclesTimestamps[$title . 'Run'];
440444

441-
if (!$to_start[$title] && $cycle_updated_timestamp && in_array($title, $auto_restarts) && ((time() - $cycle_updated_timestamp) > 30 * 60)) { //
442-
DebMes("Looks like $title is dead (updated: ".date('Y-m-d H:i:s',$cycle_updated_timestamp)."). Need to recovery", 'threads');
445+
if (!isset($to_start[$title]) && $cycle_updated_timestamp && in_array($title, $auto_restarts) && ((time() - $cycle_updated_timestamp) > 30 * 60)) { //
446+
DebMes("Looks like $title is dead (updated: " . date('Y-m-d H:i:s', $cycle_updated_timestamp) . "). Need to recovery", 'threads');
443447
registerError('cycle_hang', $title);
444448
setGlobal($title . 'Control', 'restart');
445449
}

Diff for: lib/common.class.php

+3
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ function runScriptSafe($id, $params = 0)
437437
startMeasure('runScriptSafe');
438438
$current_call = 'script.' . $id;
439439
$call_stack = array();
440+
$raiseEvent = '';
441+
$run_SafeScript = '';
442+
440443
if (is_array($params)) {
441444
if (isset($params['m_c_s']) && is_array($params['m_c_s']) && !empty($params['m_c_s'])) {
442445
$call_stack = $params['m_c_s'];

Diff for: lib/context.inc.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ function context_getcurrent($from_user_id = 0)
3636
FROM users
3737
WHERE ID = '" . (int)$from_user_id . "'";
3838
$user = SQLSelectOne($sqlQuery);
39-
if (!$user['ID'])
40-
return 0;
39+
if (!isset($user['ID'])) return 0;
4140
if ($user['ACTIVE_CONTEXT_EXTERNAL']) {
4241
return 'ext' . (int)$user['ACTIVE_CONTEXT_ID'];
4342
} else {

Diff for: lib/messages.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function say($ph, $level = 0, $member_id = 0, $source = '')
142142

143143
//dprint(date('Y-m-d H:i:s')." Say started",false);
144144

145-
verbose_log("SAY (level: $level; member: $member; source: $source): " . $ph);
145+
verbose_log("SAY (level: $level; member: $member_id; source: $source): " . $ph);
146146
//DebMes("SAY (level: $level; member: $member; source: $source): ".$ph,'say');
147147

148148
$image = '';

Diff for: lib/module.class.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,18 @@ public function checkInstalled()
347347
*/
348348
public function getConfig()
349349
{
350+
$this->config = array();
351+
350352
$sqlQuery = "SELECT *
351353
FROM project_modules
352354
WHERE NAME = '" . $this->name . "'";
353355

354356
$rec = SQLSelectOne($sqlQuery);
355-
$data = $rec["DATA"];
356-
if ($data) {
357-
$this->config = unserialize($data);
357+
if (isset($rec["DATA"])) {
358+
$data = $rec["DATA"];
359+
if ($data) {
360+
$this->config = unserialize($data);
361+
}
358362
}
359363
return $this->config;
360364
}

Diff for: lib/syncfiles.class.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ function is_dir2($d)
5656

5757
if (is_dir($d)) return true;
5858

59-
if ($node = @opendir($d)) {
60-
closedir($node);
61-
return true;
62-
}
63-
6459
return false;
6560
}
6661

@@ -517,7 +512,7 @@ function getLocalFilesTree($dir, $pattern, $ex_pattern, &$log, $verbose)
517512
if ($dir = @opendir($destination)) {
518513
while (($file = readdir($dir)) !== false) {
519514
if (Is_Dir2($destination . "/" . $file) && ($file != '.') && ($file != '..')) {
520-
$sub_ar = $this->getLocalFilesTree($destination . "/" . $file, $pattern, $ex_pattern, $log, $verbose);
515+
$sub_ar = getLocalFilesTree($destination . "/" . $file, $pattern, $ex_pattern, $log, $verbose);
521516
$res = array_merge($res, $sub_ar);
522517
} elseif (Is_File($destination . "/" . $file)) {
523518
$fl = array();

0 commit comments

Comments
 (0)