|
|
@@ -100,6 +100,92 @@ else if (empty($_SERVER["argv"]) && V::get('task', '', $_GET) == 'info') {
|
|
|
$info['max_execution_time'] = ini_get('max_execution_time');
|
|
|
$info['memory_limit'] = ini_get('memory_limit');
|
|
|
echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">info (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($info);echo'</pre>';
|
|
|
+
|
|
|
+ // $requirePermsExt = SyncPerms::getRequiredPermsExtByRecord((object)[
|
|
|
+ // 'L_APPOITMENT_USER' => "plabudda",
|
|
|
+ // 'A_ADM_COMPANY' => "",
|
|
|
+ // 'A_CLASSIFIED' => "",
|
|
|
+ // 'PARENT_L_APPOITMENT_USER' => "a.binder",
|
|
|
+ // ]);
|
|
|
+ // DBG::nicePrint($requirePermsExt, '$requirePermsExt - public for workgroup');
|
|
|
+ // $requirePermsExt = SyncPerms::getRequiredPermsExtByRecord((object)[
|
|
|
+ // 'L_APPOITMENT_USER' => "plabudda",
|
|
|
+ // 'A_ADM_COMPANY' => "2948-programista",
|
|
|
+ // 'A_CLASSIFIED' => "2948-programista",
|
|
|
+ // 'PARENT_L_APPOITMENT_USER' => "a.binder",
|
|
|
+ // ]);
|
|
|
+ // DBG::nicePrint($requirePermsExt, '$requirePermsExt - only 2948-programista read,write');
|
|
|
+ // $requirePermsExt = SyncPerms::getRequiredPermsExtByRecord((object)[
|
|
|
+ // 'L_APPOITMENT_USER' => "plabudda",
|
|
|
+ // 'A_ADM_COMPANY' => "",
|
|
|
+ // 'A_CLASSIFIED' => "2948-programista",
|
|
|
+ // 'PARENT_L_APPOITMENT_USER' => "a.binder",
|
|
|
+ // ]);
|
|
|
+ // DBG::nicePrint($requirePermsExt, '$requirePermsExt - 2948-programista read');
|
|
|
+ // $requirePermsExt = SyncPerms::getRequiredPermsExtByRecord((object)[
|
|
|
+ // 'L_APPOITMENT_USER' => "plabudda",
|
|
|
+ // 'A_ADM_COMPANY' => "2948-programista",
|
|
|
+ // 'A_CLASSIFIED' => "",
|
|
|
+ // 'PARENT_L_APPOITMENT_USER' => "a.binder",
|
|
|
+ // ]);
|
|
|
+ // DBG::nicePrint($requirePermsExt, '$requirePermsExt - 2948-programista write');
|
|
|
+ //
|
|
|
+ // $vFile = (object)[
|
|
|
+ // 'path' => 'test-file-1.txt',
|
|
|
+ // 'isDir' => false,
|
|
|
+ // 'permsExt' => [],
|
|
|
+ // ];
|
|
|
+ // $permReadDir = "list,search,readattr,readextattr,readsecurity,file_inherit,directory_inherit";
|
|
|
+ // $permWriteDir = "add_file,add_subdirectory,delete_child,writeattr,writeextattr,writesecurity,chown";
|
|
|
+ // $permReadFile = "read,execute,readattr,readextattr,readsecurity";
|
|
|
+ // $permWriteFile = "write,append,writeattr,writeextattr,writesecurity,chown";
|
|
|
+ //
|
|
|
+ // $recordPath = "/Library/Server/Web/Data/Sites/Default/PLIKI/TEST_PERMS/90";
|
|
|
+ // $filePath = "{$recordPath}/{$vFile->path}";
|
|
|
+ //
|
|
|
+ // $cmdList = SyncPerms::fixFilePerms($vFile, $requirePermsExt, $recordPath);
|
|
|
+ // DBG::nicePrint($cmdList, '$cmdList - 2948-programista write');
|
|
|
+ //
|
|
|
+ // V::exec("ls -le '{$filePath}'", $out, $ret);
|
|
|
+ // DBG::nicePrint($out, "\$out - ret({$ret})");
|
|
|
+ //
|
|
|
+ // V::exec("echo \"" . implode("\n", [
|
|
|
+ // "user:_www allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown",
|
|
|
+ // "group:27_BIALL-NET allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown",
|
|
|
+ // ]) . "\" | chmod -E '{$filePath}'", $out, $ret);
|
|
|
+ // DBG::nicePrint($out, "\$out - ret({$ret})");
|
|
|
+ //
|
|
|
+ // V::exec("ls -le '{$filePath}'", $out, $ret);
|
|
|
+ // DBG::nicePrint($out, "\$out - test 1, ret({$ret})");
|
|
|
+ //
|
|
|
+ // $aclPermsOut = implode("\n", [
|
|
|
+ // "user:_www allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown",
|
|
|
+ // "group:27_BIALL-NET allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown",
|
|
|
+ // ]);
|
|
|
+ // $aclPermsOut = implode("\n", [
|
|
|
+ // "user:_www allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown",
|
|
|
+ // "group:27_BIALL-NET allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown",
|
|
|
+ // "user:plabudda allow read,write",
|
|
|
+ // ]);
|
|
|
+ // V::exec("cd '{$recordPath}'; find . -type f | while read -r file; do echo \"fix file perms: \$file\"; echo \"{$aclPermsOut}\" | chmod -E \"\${file}\"; done", $out, $ret);
|
|
|
+ // DBG::nicePrint($out, "\$out - ret({$ret})");
|
|
|
+ //
|
|
|
+ // V::exec("ls -le '{$filePath}'", $out, $ret);
|
|
|
+ // DBG::nicePrint($out, "\$out - test 2, ret({$ret})");
|
|
|
+ //
|
|
|
+ // $testPermsFile = "{$recordPath}/perms-90.txt";
|
|
|
+ // DBG::nicePrint(explode("\n", file_get_contents($testPermsFile)), "testPermsFile - before add line");
|
|
|
+ // $lineToAdd = "user:plabudda allow read,write";
|
|
|
+ // V::exec("cat '{$testPermsFile}' | grep '{$lineToAdd}' || echo \"{$lineToAdd}\" >> '{$testPermsFile}'", $out, $ret);
|
|
|
+ // DBG::nicePrint($out, "\$out - add line, ret({$ret})");
|
|
|
+ // DBG::nicePrint(explode("\n", file_get_contents($testPermsFile)), "testPermsFile - after add line");
|
|
|
+ //
|
|
|
+ // { // TODO: add to instalator / install check / ?Status
|
|
|
+ // $lineToAdd = "_www ALL = NOPASWD: '" . APP_PATH_ROOT . "/SE/index-cli.php'";
|
|
|
+ // $destFile = "/etc/sudoers";
|
|
|
+ // V::exec("cat '{$destFile}' | grep '{$lineToAdd}' || echo \"{$lineToAdd}\" >> '{$destFile}'", $out, $ret);
|
|
|
+ // // TODO: check if sudo index-cli.php can exec("sudo ...")
|
|
|
+ // }
|
|
|
}
|
|
|
else if (empty($_SERVER["argv"]) && V::get('task', '', $_GET) == 'users') {
|
|
|
SyncPerms::run(null, null, 'users', null);
|
|
|
@@ -474,8 +560,6 @@ class SyncPerms {
|
|
|
}
|
|
|
|
|
|
public static function installTable() {
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
$sql = "
|
|
|
CREATE TABLE IF NOT EXISTS `_SYNC_FILE_PERMS` (
|
|
|
`ID` int(11) NOT NULL AUTO_INCREMENT,
|
|
|
@@ -491,43 +575,57 @@ class SyncPerms {
|
|
|
UNIQUE KEY `ID_PROJECT` (`ID_PROJECT`)
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin2 ;
|
|
|
";
|
|
|
- $db->query($sql);
|
|
|
-
|
|
|
- $sql = " DROP TRIGGER IF EXISTS `KORESP_change_ID_PROJECT`; ";
|
|
|
- $db->query($sql);
|
|
|
- $sql = "
|
|
|
- CREATE DEFINER=`root`@`localhost` TRIGGER `KORESP_change_ID_PROJECT` AFTER UPDATE ON `IN7_DZIENNIK_KORESP`
|
|
|
- FOR EACH ROW BEGIN
|
|
|
- IF (NEW.`ID_PROJECT` != OLD.`ID_PROJECT` and NEW.`ID_PROJECT` > 0) or OLD.`M_DIST_FILES`!=NEW.`M_DIST_FILES` THEN
|
|
|
- update `_SYNC_FILE_PERMS` as s set
|
|
|
- s.`A_SYNCHRONIZED`=0
|
|
|
- where
|
|
|
- s.`ID_PROJECT`=NEW.`ID_PROJECT`
|
|
|
- or s.`ID_PROJECT`=OLD.`ID_PROJECT`;
|
|
|
- END IF;
|
|
|
- END
|
|
|
- ";
|
|
|
- $db->query($sql);
|
|
|
-
|
|
|
- $sql = " DROP TRIGGER IF EXISTS `KORESP_add_ID_PROJECT`; ";
|
|
|
- $db->query($sql);
|
|
|
- $sql = "
|
|
|
- CREATE DEFINER=`root`@`localhost` TRIGGER `KORESP_add_ID_PROJECT` AFTER INSERT ON `IN7_DZIENNIK_KORESP`
|
|
|
- FOR EACH ROW BEGIN
|
|
|
- IF NEW.`ID_PROJECT` > 0 THEN
|
|
|
- update `_SYNC_FILE_PERMS` as s set
|
|
|
- s.`A_SYNCHRONIZED`=0
|
|
|
- where
|
|
|
- s.`ID_PROJECT`=NEW.`ID_PROJECT`;
|
|
|
- END IF;
|
|
|
- END
|
|
|
- ";
|
|
|
- $db->query($sql);
|
|
|
-
|
|
|
- if (V::get('DBG', '', $_GET, 'int') > 0) {
|
|
|
- if ($db->has_errors()) {
|
|
|
- echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">DB errors (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($db->get_errors());echo'</pre>';
|
|
|
- }
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+
|
|
|
+ try {
|
|
|
+ $sql = " DROP TRIGGER IF EXISTS `KORESP_change_ID_PROJECT`; ";
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ // TODO: SKIP - BUG after upgrade mysql - @see https://dev.mysql.com/doc/refman/5.5/en/upgrading-from-previous-series.html
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $sql = "
|
|
|
+ CREATE DEFINER=`root`@`localhost` TRIGGER `KORESP_change_ID_PROJECT` AFTER UPDATE ON `IN7_DZIENNIK_KORESP`
|
|
|
+ FOR EACH ROW BEGIN
|
|
|
+ IF (NEW.`ID_PROJECT` != OLD.`ID_PROJECT` and NEW.`ID_PROJECT` > 0) or OLD.`M_DIST_FILES`!=NEW.`M_DIST_FILES` THEN
|
|
|
+ update `_SYNC_FILE_PERMS` as s set
|
|
|
+ s.`A_SYNCHRONIZED`=0
|
|
|
+ where
|
|
|
+ s.`ID_PROJECT`=NEW.`ID_PROJECT`
|
|
|
+ or s.`ID_PROJECT`=OLD.`ID_PROJECT`;
|
|
|
+ END IF;
|
|
|
+ END
|
|
|
+ ";
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $sql = " DROP TRIGGER IF EXISTS `KORESP_add_ID_PROJECT`; ";
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ // TODO: SKIP - BUG after upgrade mysql - @see https://dev.mysql.com/doc/refman/5.5/en/upgrading-from-previous-series.html
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $sql = "
|
|
|
+ CREATE DEFINER=`root`@`localhost` TRIGGER `KORESP_add_ID_PROJECT` AFTER INSERT ON `IN7_DZIENNIK_KORESP`
|
|
|
+ FOR EACH ROW BEGIN
|
|
|
+ IF NEW.`ID_PROJECT` > 0 THEN
|
|
|
+ update `_SYNC_FILE_PERMS` as s set
|
|
|
+ s.`A_SYNCHRONIZED`=0
|
|
|
+ where
|
|
|
+ s.`ID_PROJECT`=NEW.`ID_PROJECT`;
|
|
|
+ END IF;
|
|
|
+ END
|
|
|
+ ";
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -557,9 +655,8 @@ class SyncPerms {
|
|
|
}
|
|
|
|
|
|
public static function generateTasksUpdated() {
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
- $sqlTest = "select p.ID, p.`L_APPOITMENT_USER`, p.`A_ADM_COMPANY`, p.`A_CLASSIFIED`, s. *
|
|
|
+ $sqlTest = "
|
|
|
+ select p.ID, p.`L_APPOITMENT_USER`, p.`A_ADM_COMPANY`, p.`A_CLASSIFIED`, s. *
|
|
|
from `_SYNC_FILE_PERMS` as s, `IN7_MK_BAZA_DYSTRYBUCJI` as p, `IN7_MK_BAZA_DYSTRYBUCJI` as pp
|
|
|
where
|
|
|
s.`ID_PROJECT`=p.`ID` and pp.`ID`=p.`P_ID`
|
|
|
@@ -587,16 +684,24 @@ class SyncPerms {
|
|
|
or s.`PARENT_L_APPOITMENT_USER`!=pp.`L_APPOITMENT_USER`
|
|
|
)
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static function generateTasksNewRecords() {
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
$sql = "insert ignore into `_SYNC_FILE_PERMS` (`ID_PROJECT`, `L_APPOITMENT_USER`, `A_ADM_COMPANY`, `A_CLASSIFIED`, `PARENT_L_APPOITMENT_USER`)
|
|
|
values (-1, '', '', '', '');
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
+ }
|
|
|
|
|
|
$sql = "insert ignore into `_SYNC_FILE_PERMS` (`ID_PROJECT`, `L_APPOITMENT_USER`, `A_ADM_COMPANY`, `A_CLASSIFIED`, `PARENT_L_APPOITMENT_USER`)
|
|
|
select p.`ID`, p.`L_APPOITMENT_USER`, p.`A_ADM_COMPANY`, p.`A_CLASSIFIED`, pp.`L_APPOITMENT_USER`
|
|
|
@@ -604,23 +709,24 @@ class SyncPerms {
|
|
|
left join `IN7_MK_BAZA_DYSTRYBUCJI` as pp on (pp.`ID`=p.`P_ID`)
|
|
|
where p.`A_STATUS`!='DELETED'
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Znajdź najstarszy aktualizowany projekt.
|
|
|
*/
|
|
|
public static function getTask() {
|
|
|
- $task = null;
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
-
|
|
|
$sqlWhereProjID = " s.`A_SYNCHRONIZED`=0 ";
|
|
|
- if (($projID = V::get('PROJ_ID', '', $_GET, 'int')) > 0){
|
|
|
+ if (($projID = V::get('PROJ_ID', '', $_GET, 'int')) > 0) {
|
|
|
$sqlWhereProjID = " s.`ID_PROJECT`='{$projID}' ";
|
|
|
}
|
|
|
-
|
|
|
- $sql = "select s.*
|
|
|
+ $sql = "
|
|
|
+ select s.*
|
|
|
, p.`L_APPOITMENT_USER` as p__L_APPOITMENT_USER
|
|
|
, p.`A_ADM_COMPANY` as p__A_ADM_COMPANY
|
|
|
, p.`A_CLASSIFIED` as p__A_CLASSIFIED
|
|
|
@@ -631,84 +737,82 @@ class SyncPerms {
|
|
|
from `_SYNC_FILE_PERMS` as s
|
|
|
left join `IN7_MK_BAZA_DYSTRYBUCJI` as p on(p.`ID`=s.`ID_PROJECT`)
|
|
|
left join `IN7_MK_BAZA_DYSTRYBUCJI` as pp on(pp.`ID`=p.`P_ID`)
|
|
|
- where
|
|
|
- {$sqlWhereProjID}
|
|
|
+ where {$sqlWhereProjID}
|
|
|
order by s.`A_LAST_SYNC` asc, s.`ID` asc
|
|
|
limit 1
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- if ($r = $db->fetch($res)) {
|
|
|
- $r->A_SYNC_RESULT = (!$r->A_SYNC_RESULT)? new stdClass() : json_decode($r->A_SYNC_RESULT);
|
|
|
- $task = $r;
|
|
|
+ try {
|
|
|
+ $task = DB::getPDO()->fetchFirst($sql);
|
|
|
+ if ($task) {
|
|
|
+ $task['A_SYNC_RESULT'] = (!$task['A_SYNC_RESULT'])? new stdClass() : json_decode($task['A_SYNC_RESULT']);
|
|
|
+ return (object)$task;
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
}
|
|
|
- return $task;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
public static function getTaskNewerUsers() {
|
|
|
- $task = null;
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
- $sql = "select s.*
|
|
|
+ $sql = "
|
|
|
+ select s.*
|
|
|
from `_SYNC_FILE_PERMS` as s
|
|
|
where s.`ID_PROJECT`=-2
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- if ($r = $db->fetch($res)) {
|
|
|
- $task = $r;
|
|
|
+ try {
|
|
|
+ $task = DB::getPDO()->fetchFirst($sql);
|
|
|
+ if ($task) {
|
|
|
+ return (object)$task;
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
}
|
|
|
|
|
|
- if (!$task) {
|
|
|
- $task = new stdClass();
|
|
|
- $task->ID_PROJECT = -2;
|
|
|
- $task->A_SYNC_RESULT = new stdClass();
|
|
|
- $task->A_LAST_SYNC = '';//mktime(date("H"), date("i") - 10, date("s"), date("n"), date("j"), date("Y"));
|
|
|
- //$task->A_LAST_SYNC = date("Y-m-d H:i", $task->A_LAST_SYNC);
|
|
|
- }
|
|
|
- return $task;
|
|
|
+ return (object)[
|
|
|
+ 'ID_PROJECT' => -2,
|
|
|
+ 'A_SYNC_RESULT' => new stdClass(),
|
|
|
+ 'A_LAST_SYNC' => '', // date("Y-m-d H:i", mktime(date("H"), date("i") - 10, date("s"), date("n"), date("j"), date("Y"))),
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
public static function getTaskNewFiles() {
|
|
|
- $task = null;
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
- $sql = "select s.*
|
|
|
+ $sql = "
|
|
|
+ select s.*
|
|
|
from `_SYNC_FILE_PERMS` as s
|
|
|
where s.`ID_PROJECT`=-1
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- if ($r = $db->fetch($res)) {
|
|
|
- $task = $r;
|
|
|
+ try {
|
|
|
+ $task = DB::getPDO()->fetchFirst($sql);
|
|
|
+ if ($task) {
|
|
|
+ return (object)$task;
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
}
|
|
|
|
|
|
- if (!$task) {
|
|
|
- $task = new stdClass();
|
|
|
- $task->ID_PROJECT = -1;
|
|
|
- $task->A_SYNC_RESULT = new stdClass();
|
|
|
- $task->A_LAST_SYNC = mktime(date("H"), date("i") - 10, date("s"), date("n"), date("j"), date("Y"));
|
|
|
- $task->A_LAST_SYNC = date("Y-m-d H:i", $task->A_LAST_SYNC);
|
|
|
- }
|
|
|
- return $task;
|
|
|
+ return (object)[
|
|
|
+ 'ID_PROJECT' => -1,
|
|
|
+ 'A_SYNC_RESULT' => new stdClass(),
|
|
|
+ 'A_LAST_SYNC' => date("Y-m-d H:i", mktime(date("H"), date("i") - 10, date("s"), date("n"), date("j"), date("Y"))),
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
public static function saveTask($idProject, $taskDone = 1, $result = null) {
|
|
|
- $task = null;
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
- $sqlResult = '';
|
|
|
- if ($result) {
|
|
|
- $resultJson = json_encode($result);
|
|
|
- $resultJson = $db->_($resultJson);
|
|
|
- $sqlResult .= " , s.`A_SYNC_RESULT`='{$resultJson}' ";
|
|
|
- }
|
|
|
- $sql = "update `_SYNC_FILE_PERMS` as s
|
|
|
+ $sqlResult = ($result)
|
|
|
+ ? " , s.`A_SYNC_RESULT` = " . DB::getPDO()->quote( json_encode($result) )
|
|
|
+ : '';
|
|
|
+ $sql = "
|
|
|
+ update `_SYNC_FILE_PERMS` as s
|
|
|
set
|
|
|
- s.`A_LAST_SYNC`=NOW()
|
|
|
- , s.`A_SYNCHRONIZED`={$taskDone}
|
|
|
+ s.`A_LAST_SYNC` = NOW()
|
|
|
+ , s.`A_SYNCHRONIZED` = {$taskDone}
|
|
|
{$sqlResult}
|
|
|
- where s.`ID_PROJECT`={$idProject}
|
|
|
+ where s.`ID_PROJECT` = {$idProject}
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- return $task;
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
}
|
|
|
|
|
|
public static function executeTask(&$task) {
|
|
|
@@ -793,17 +897,11 @@ class SyncPerms {
|
|
|
public static function getActiveLoginList() {
|
|
|
static $activeLoginList;
|
|
|
if (!is_array($activeLoginList)) {
|
|
|
- $activeLoginList = array();
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
- $sql = "select u.`ADM_ACCOUNT`
|
|
|
+ $activeLoginList = DB::getPDO()->fetchValuesList("
|
|
|
+ select u.`ADM_ACCOUNT`
|
|
|
from `ADMIN_USERS` as u
|
|
|
where u.`A_STATUS` = 'NORMAL'
|
|
|
- ";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $activeLoginList[] = $r->ADM_ACCOUNT;
|
|
|
- }
|
|
|
+ ");
|
|
|
}
|
|
|
return $activeLoginList;
|
|
|
}
|
|
|
@@ -866,9 +964,6 @@ class SyncPerms {
|
|
|
* @return TODO: object to store in task->A_SYNC_RESULT
|
|
|
*/
|
|
|
public static function fixLastModifiedFiles($task) {
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
-
|
|
|
if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fixLastModifiedFiles (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("fixLastModifiedFiles");echo'</pre>';}
|
|
|
|
|
|
$PROJ_mount_point = FoldersConfig::get('IN7_MK_BAZA_DYSTRYBUCJI_COLUMN', 'mount_point');
|
|
|
@@ -941,7 +1036,8 @@ class SyncPerms {
|
|
|
if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">foundProjectFiles (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): '."path: {$PROJ_mount_point}\n";print_r($foundProjectFiles);echo'</pre>';}
|
|
|
|
|
|
if (!empty($foundProjectFiles)) {
|
|
|
- $sql = "select p.`ID`
|
|
|
+ $sql = "
|
|
|
+ select p.`ID`
|
|
|
, p.`L_APPOITMENT_USER`
|
|
|
, p.`A_ADM_COMPANY`
|
|
|
, p.`A_CLASSIFIED`
|
|
|
@@ -950,8 +1046,9 @@ class SyncPerms {
|
|
|
left join IN7_MK_BAZA_DYSTRYBUCJI as pp on (pp.ID=p.P_ID)
|
|
|
where p.`ID` in (" . implode(',', array_keys($foundProjectFiles)) . ")
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
+ $rows = DB::getPDO()->fetchAll($sql);
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $r = (object)$row;
|
|
|
|
|
|
$requirePermsExt = self::getRequiredPermsExtByRecord($r);
|
|
|
|
|
|
@@ -977,25 +1074,21 @@ class SyncPerms {
|
|
|
}
|
|
|
|
|
|
public static function fixProjectKoresp($project, $folderPismaPath) {
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
-
|
|
|
$PISMA_mount_point = FoldersConfig::get('IN7_DZIENNIK_KORESP_COLUMN', 'mount_point');
|
|
|
$PISMA_mount_point = rtrim($PISMA_mount_point, '/');
|
|
|
- $pismaList = array();
|
|
|
// $PISMA_mount_point / {TYP_KORESP} / {ID} . *
|
|
|
- $sql = "select k.`ID`
|
|
|
+ $sql = "
|
|
|
+ select k.`ID`
|
|
|
, k.`K_TYP_KORESP`
|
|
|
from `IN7_DZIENNIK_KORESP` as k
|
|
|
where k.`ID_PROJECT`={$project->ID}
|
|
|
order by k.`ID` DESC
|
|
|
limit 100
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $pismaList[$r->ID] = $r->K_TYP_KORESP;// TODO: K_TYP_KORESP not used
|
|
|
- }
|
|
|
-
|
|
|
+ $pismaList = array_map(function ($row) {
|
|
|
+ return $row['K_TYP_KORESP']; // TODO: K_TYP_KORESP not used
|
|
|
+ }, DB::getPDO()->fetchAllByKey($sql, 'ID'));
|
|
|
+ // $PISMA_mount_point / {TYP_KORESP} / {ID} . *
|
|
|
if (empty($pismaList)) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -1347,9 +1440,6 @@ R list, search, readattr, readext
|
|
|
* @returns array - last modified project ids.
|
|
|
*/
|
|
|
public static function fixLastModifiedByFiles() {// TODO: RMME
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
-
|
|
|
if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fixLastModifiedByFiles (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("fixLastModifiedByFiles");echo'</pre>';}
|
|
|
|
|
|
/*
|
|
|
@@ -1395,7 +1485,8 @@ R list, search, readattr, readext
|
|
|
if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">foundProjectIds (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): '."path: {$PROJ_mount_point}\n";print_r($foundProjectIds);echo'</pre>';}
|
|
|
|
|
|
if (!empty($foundProjectIds)) {
|
|
|
- $sql = "select p.`ID`
|
|
|
+ $sql = "
|
|
|
+ select p.`ID`
|
|
|
, p.`L_APPOITMENT_USER`
|
|
|
, p.`A_ADM_COMPANY`
|
|
|
, p.`A_CLASSIFIED`
|
|
|
@@ -1404,8 +1495,9 @@ R list, search, readattr, readext
|
|
|
left join IN7_MK_BAZA_DYSTRYBUCJI as pp on (pp.ID=p.P_ID)
|
|
|
where p.`ID` in (" . implode(',', array_keys($foundProjectIds)) . ")
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
+ $rows = DB::getPDO()->fetchAll($sql);
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $r = (object)$row;
|
|
|
$mainFolder = $foundProjectIds[$r->ID];
|
|
|
|
|
|
$cmdList = self::fixProject($r, $mainFolder, $PROJ_mount_point);
|
|
|
@@ -1420,9 +1512,6 @@ R list, search, readattr, readext
|
|
|
}
|
|
|
|
|
|
public static function fixLastModifiedByDB($fixedProjIds) {// TODO: RMME
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
-
|
|
|
if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fixLastModifiedByDB (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("fixLastModifiedByDB");echo'</pre>';}
|
|
|
|
|
|
$sqlWhereAdd = '';
|
|
|
@@ -1430,9 +1519,9 @@ R list, search, readattr, readext
|
|
|
$sqlWhereAdd = " and p.`ID` not in (" . implode(',', $fixedProjIds) . ") ";
|
|
|
}
|
|
|
|
|
|
- $projectList = array();
|
|
|
$lastRunDate = self::getLastRunDate();
|
|
|
- $sql = "select p.`ID`
|
|
|
+ $sql = "
|
|
|
+ select p.`ID`
|
|
|
, p.`L_APPOITMENT_USER`
|
|
|
, p.`A_ADM_COMPANY`
|
|
|
, p.`A_CLASSIFIED`
|
|
|
@@ -1446,10 +1535,9 @@ R list, search, readattr, readext
|
|
|
{$sqlWhereAdd}
|
|
|
";
|
|
|
if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $projectList[$r->ID] = $r;
|
|
|
- }
|
|
|
+ $projectList = array_map(function ($row) {
|
|
|
+ return (object)$row;
|
|
|
+ }, DB::getPDO()->fetchAllByKey($sql, 'ID'));
|
|
|
|
|
|
if(V::get('DBG', '', $_GET, 'int') > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">projectList (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($projectList);echo'</pre>';}
|
|
|
|
|
|
@@ -1538,16 +1626,14 @@ R list, search, readattr, readext
|
|
|
}
|
|
|
|
|
|
public static function getUsersNewerThen($datetime) {
|
|
|
- $users = array();
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
$sqlWhereAdd = "";
|
|
|
if ($datetime) {
|
|
|
$sqlWhereAdd = " and ( u.`A_RECORD_CREATE_DATE`>'{$datetime}' or u.`A_RECORD_UPDATE_DATE`>'{$datetime}' )";
|
|
|
} else {
|
|
|
// TODO: error datetime not set
|
|
|
}
|
|
|
- $sql = "select u.ID
|
|
|
+ $sql = "
|
|
|
+ select u.ID
|
|
|
, u.`ADM_ACCOUNT`
|
|
|
, u.`ADM_NAME`
|
|
|
, u.`A_STATUS`
|
|
|
@@ -1555,18 +1641,14 @@ R list, search, readattr, readext
|
|
|
where
|
|
|
u.`A_STATUS` in('NORMAL', 'DELETED')
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $users[$r->ADM_ACCOUNT] = $r;
|
|
|
- }
|
|
|
- return $users;
|
|
|
+ return array_map(function ($row) {
|
|
|
+ return (object)$row;
|
|
|
+ }, DB::getPDO()->fetchAllByKey($sql, 'ADM_ACCOUNT'));
|
|
|
}
|
|
|
|
|
|
public static function getUsersAll() {
|
|
|
- $users = array();
|
|
|
- $db = DB::getDB();
|
|
|
- if (!$db) die("DB Error: No DB! L." . __LINE__);
|
|
|
- $sql = "select u.ID
|
|
|
+ $sql = "
|
|
|
+ select u.ID
|
|
|
, u.`ADM_ACCOUNT`
|
|
|
, u.`ADM_NAME`
|
|
|
, u.`A_STATUS`
|
|
|
@@ -1574,11 +1656,9 @@ R list, search, readattr, readext
|
|
|
where
|
|
|
u.`A_STATUS` in('NORMAL', 'DELETED')
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $users[$r->ADM_ACCOUNT] = $r;
|
|
|
- }
|
|
|
- return $users;
|
|
|
+ return array_map(function ($row) {
|
|
|
+ return (object)$row;
|
|
|
+ }, DB::getPDO()->fetchAllByKey($sql, 'ADM_ACCOUNT'));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -1616,21 +1696,13 @@ class SyncPermsCustomTables {
|
|
|
}
|
|
|
|
|
|
public function fetchConfig() {
|
|
|
- $this->_db = DB::getDB();
|
|
|
- if (!$this->_db) die("DB Error: No DB! L." . __LINE__);
|
|
|
-
|
|
|
- $tbls = array();
|
|
|
- $sql = "select c.`CONF_VAL` as tbl_names
|
|
|
+ $sql = "
|
|
|
+ select c.`CONF_VAL` as tbl_names
|
|
|
from `CRM_CONFIG` as c
|
|
|
where c.`CONF_KEY`='_SYNC_TABLE_FILE_PERMS__TablesList'
|
|
|
";
|
|
|
- $res = $this->_db->query($sql);
|
|
|
- while ($r = $this->_db->fetch($res)) {
|
|
|
- if (!empty($r->tbl_names)) {
|
|
|
- $tbls = explode("\n", $r->tbl_names);
|
|
|
- }
|
|
|
- }
|
|
|
- //echo "DBG:" . __LINE__ . ":" . __FUNCTION__ . "(): tbls [" . implode(',', $tbls) . "]\n";
|
|
|
+ $tblNames = DB::getPDO()->fetchValue($sql);
|
|
|
+ $tbls = (!empty($tblNames)) ? explode("\n", $tblNames) : [];
|
|
|
$configTbls = array();
|
|
|
Lib::loadClass('FoldersConfig');
|
|
|
if (!empty($tbls)) {
|
|
|
@@ -1653,7 +1725,6 @@ class SyncPermsCustomTables {
|
|
|
|
|
|
public function installTable() {
|
|
|
if (!$this->_tbls) return;
|
|
|
- if (!$this->_db) die("DB Error: No DB! L." . __LINE__);
|
|
|
$sql = "
|
|
|
CREATE TABLE IF NOT EXISTS `{$this->_syncTblName}` (
|
|
|
`ID` int(11) NOT NULL AUTO_INCREMENT,
|
|
|
@@ -1671,47 +1742,53 @@ class SyncPermsCustomTables {
|
|
|
UNIQUE KEY `TBL` (`TBL_NAME`, `TBL_ID`)
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin2 ;
|
|
|
";
|
|
|
- $this->_db->query($sql);
|
|
|
- if ($this->_db->has_errors()) {
|
|
|
- print_r($this->_db->get_errors());
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function generateTasksNewRecords() {
|
|
|
if (!$this->_tbls) return;
|
|
|
- if (!$this->_db) die("DB Error: No DB! L." . __LINE__);
|
|
|
|
|
|
$sqlValues = array();
|
|
|
foreach ($this->_tbls as $tblName => $tblConf) {
|
|
|
$sqlValues[] = "('{$tblName}', -1, '', '', '', '')";
|
|
|
}
|
|
|
$sqlValues = implode(',', $sqlValues);
|
|
|
- $sql = "insert ignore into `{$this->_syncTblName}` (`TBL_NAME`, `TBL_ID`, `L_APPOITMENT_USER`, `A_ADM_COMPANY`, `A_CLASSIFIED`, `PARENT_L_APPOITMENT_USER`)
|
|
|
+ $sql = "
|
|
|
+ insert ignore into `{$this->_syncTblName}` (`TBL_NAME`, `TBL_ID`, `L_APPOITMENT_USER`, `A_ADM_COMPANY`, `A_CLASSIFIED`, `PARENT_L_APPOITMENT_USER`)
|
|
|
values {$sqlValues};
|
|
|
";
|
|
|
- $res = $this->_db->query($sql);
|
|
|
- if ($this->_db->has_errors()) {
|
|
|
- print_r($this->_db->get_errors());
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
}
|
|
|
|
|
|
foreach ($this->_tbls as $tblName => $tblConf) {
|
|
|
- $sql = "insert ignore into `{$this->_syncTblName}` (`TBL_NAME`, `TBL_ID`, `L_APPOITMENT_USER`, `A_ADM_COMPANY`, `A_CLASSIFIED`, `PARENT_L_APPOITMENT_USER`)
|
|
|
+ $sql = "
|
|
|
+ insert ignore into `{$this->_syncTblName}` (`TBL_NAME`, `TBL_ID`, `L_APPOITMENT_USER`, `A_ADM_COMPANY`, `A_CLASSIFIED`, `PARENT_L_APPOITMENT_USER`)
|
|
|
select '{$tblName}' as TBL_NAME
|
|
|
, t.`ID`, t.`L_APPOITMENT_USER`, t.`A_ADM_COMPANY`, t.`A_CLASSIFIED`
|
|
|
, '' as PARENT_L_APPOITMENT_USER -- pp.`L_APPOITMENT_USER`
|
|
|
from `{$tblName}` as t
|
|
|
where t.`A_STATUS`!='DELETED'
|
|
|
";
|
|
|
- $res = $this->_db->query($sql);
|
|
|
- if ($this->_db->has_errors()) {
|
|
|
- print_r($this->_db->get_errors());
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function generateTasksUpdated() {
|
|
|
if (!$this->_tbls) return;
|
|
|
- if (!$this->_db) die("DB Error: No DB! L." . __LINE__);
|
|
|
|
|
|
foreach ($this->_tbls as $tblName => $tblConf) {
|
|
|
$sql = "update `{$this->_syncTblName}` as s
|
|
|
@@ -1734,9 +1811,11 @@ class SyncPermsCustomTables {
|
|
|
-- or s.`PARENT_L_APPOITMENT_USER`!=pt.`L_APPOITMENT_USER`
|
|
|
)
|
|
|
";
|
|
|
- $res = $this->_db->query($sql);
|
|
|
- if ($this->_db->has_errors()) {
|
|
|
- print_r($this->_db->get_errors());
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ echo "DB ERR L." . __LINE__ . ": " . $e->getMessage() . "\n";
|
|
|
+ trigger_error("DB ERR L." . __LINE__ . ": " . $e->getMessage(), E_USER_WARNING);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1753,30 +1832,24 @@ class SyncPermsCustomTables {
|
|
|
|
|
|
private function _getTaskNewFiles($tblName) {
|
|
|
$task = null;
|
|
|
- if (!$this->_db) die("DB Error: No DB! L." . __LINE__);
|
|
|
|
|
|
- $sql = "select s.*
|
|
|
+ $sql = "
|
|
|
+ select s.*
|
|
|
from `{$this->_syncTblName}` as s
|
|
|
where s.`TBL_ID`=-1 and s.`TBL_NAME`='{$tblName}'
|
|
|
";
|
|
|
- $res = $this->_db->query($sql);
|
|
|
- if ($r = $this->_db->fetch($res)) {
|
|
|
- $task = $r;
|
|
|
- }
|
|
|
-
|
|
|
- if (!$task) {
|
|
|
- $task = new stdClass();
|
|
|
- $task->TBL_NAME = $tblName;
|
|
|
- $task->TBL_ID = -1;
|
|
|
- $task->A_SYNC_RESULT = new stdClass();
|
|
|
- $task->A_LAST_SYNC = mktime(date("H"), date("i") - 10, date("s"), date("n"), date("j"), date("Y"));
|
|
|
- $task->A_LAST_SYNC = date("Y-m-d H:i", $task->A_LAST_SYNC);
|
|
|
- }
|
|
|
- return $task;
|
|
|
+ $task = DB::getPDO()->fetchFirst($sql);
|
|
|
+ return ($task)
|
|
|
+ ? (object)$task
|
|
|
+ : (object)[
|
|
|
+ 'TBL_NAME' => $tblName,
|
|
|
+ 'TBL_ID' => -1,
|
|
|
+ 'A_SYNC_RESULT' => new stdClass(),
|
|
|
+ 'A_LAST_SYNC' => date("Y-m-d H:i", mktime(date("H"), date("i") - 10, date("s"), date("n"), date("j"), date("Y"))),
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
private function _fixLastModifiedFiles($task) {
|
|
|
- if (!$this->_db) die("DB Error: No DB! L." . __LINE__);
|
|
|
$tblName = $task->TBL_NAME;
|
|
|
|
|
|
if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fixLastModifiedFiles (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("fixLastModifiedFiles");echo'</pre>';}
|
|
|
@@ -1872,7 +1945,8 @@ class SyncPermsCustomTables {
|
|
|
|
|
|
if (!empty($foundTblFiles)) {
|
|
|
$rowsIds = array_keys($foundTblFiles);
|
|
|
- $sql = "select t.`ID`
|
|
|
+ $sql = "
|
|
|
+ select t.`ID`
|
|
|
, t.`L_APPOITMENT_USER`
|
|
|
, t.`A_ADM_COMPANY`
|
|
|
, t.`A_CLASSIFIED`
|
|
|
@@ -1881,8 +1955,9 @@ class SyncPermsCustomTables {
|
|
|
-- left join `{$task->TBL_NAME}` as pt on (pt.ID=t.P_ID)
|
|
|
where t.`ID` in (" . implode(',', $rowsIds) . ")
|
|
|
";
|
|
|
- $res = $this->_db->query($sql);
|
|
|
- while ($r = $this->_db->fetch($res)) {
|
|
|
+ $rows = DB::getPDO()->fetchAll($sql);
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $r = (object)$row;
|
|
|
|
|
|
$requirePermsExt = $this->_getRequiredPermsExtByRecord($r);
|
|
|
|
|
|
@@ -2070,37 +2145,31 @@ class SyncPermsCustomTables {
|
|
|
}
|
|
|
|
|
|
public function _fetchActiveLoginList() {
|
|
|
- if (!$this->_db) die("DB Error: No DB! L." . __LINE__);
|
|
|
if (!is_array($this->_activeLoginList)) {
|
|
|
$this->_activeLoginList = array();
|
|
|
- $sql = "select u.`ADM_ACCOUNT`
|
|
|
+ $sql = "
|
|
|
+ select u.`ADM_ACCOUNT`
|
|
|
from `ADMIN_USERS` as u
|
|
|
where u.`A_STATUS` = 'NORMAL'
|
|
|
";
|
|
|
- $res = $this->_db->query($sql);
|
|
|
- while ($r = $this->_db->fetch($res)) {
|
|
|
- $this->_activeLoginList[] = $r->ADM_ACCOUNT;
|
|
|
- }
|
|
|
+ $this->_activeLoginList = DB::getPDO()->fetchValuesList($sql);
|
|
|
}
|
|
|
return $this->_activeLoginList;
|
|
|
}
|
|
|
|
|
|
private function _saveTask($tblName, $tblId, $taskDone = 1, $result = null) {
|
|
|
- if (!$this->_db) die("DB Error: No DB! L." . __LINE__);
|
|
|
- $sqlResult = '';
|
|
|
- if ($result) {
|
|
|
- $resultJson = json_encode($result);
|
|
|
- $resultJson = $this->_db->_($resultJson);
|
|
|
- $sqlResult .= " , s.`A_SYNC_RESULT`='{$resultJson}' ";
|
|
|
- }
|
|
|
- $sql = "update `{$this->_syncTblName}` as s
|
|
|
+ $sqlResult = ($result)
|
|
|
+ ? " , s.`A_SYNC_RESULT` = " . DB::getPDO()->quote( json_encode($result) )
|
|
|
+ : '';
|
|
|
+ $sql = "
|
|
|
+ update `{$this->_syncTblName}` as s
|
|
|
set
|
|
|
s.`A_LAST_SYNC`=NOW()
|
|
|
, s.`A_SYNCHRONIZED`={$taskDone}
|
|
|
{$sqlResult}
|
|
|
where s.`TBL_ID`={$tblId} and s.`TBL_NAME`='{$tblName}'
|
|
|
";
|
|
|
- $res = $this->_db->query($sql);
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
}
|
|
|
|
|
|
public function executeTask($tblName, $tblId) {
|
|
|
@@ -2136,7 +2205,6 @@ class SyncPermsCustomTables {
|
|
|
}
|
|
|
|
|
|
private function _getTask($tblName, $tblId = null) {
|
|
|
- if (!$this->_db) die("DB Error: No DB! L." . __LINE__);
|
|
|
$task = null;
|
|
|
|
|
|
$recordFieldList = $this->_getRecordFieldList($tblName);
|
|
|
@@ -2153,7 +2221,8 @@ class SyncPermsCustomTables {
|
|
|
$sqlTblId = "and s.`TBL_ID`!=-1";
|
|
|
if ($tblId > 0) $sqlTblId = "and s.`TBL_ID`='{$tblId}'";
|
|
|
|
|
|
- $sql = "select s.*
|
|
|
+ $sql = "
|
|
|
+ select s.*
|
|
|
, {$sqlRecordFields}
|
|
|
-- , pt.`L_APPOITMENT_USER` as p__PARENT_L_APPOITMENT_USER
|
|
|
from `{$this->_syncTblName}` as s
|
|
|
@@ -2167,8 +2236,9 @@ class SyncPermsCustomTables {
|
|
|
order by s.`A_LAST_SYNC` asc, s.`ID` asc
|
|
|
limit 1
|
|
|
";
|
|
|
- $res = $this->_db->query($sql);
|
|
|
- if ($r = $this->_db->fetch($res)) {
|
|
|
+ $row = DB::getPDO()->fetchFirst($sql);
|
|
|
+ if ($row) {
|
|
|
+ $r = (object)$row;
|
|
|
$r->A_SYNC_RESULT = (!$r->A_SYNC_RESULT)? new stdClass() : json_decode($r->A_SYNC_RESULT);
|
|
|
$task = $r;
|
|
|
$task->record = new stdClass();
|