Browse Source

fixed code in bash sync perms

Piotr Labudda 10 năm trước cách đây
mục cha
commit
54cfc5e7d0
1 tập tin đã thay đổi với 312 bổ sung314 xóa
  1. 312 314
      SE/bash_sync_perms.php

+ 312 - 314
SE/bash_sync_perms.php

@@ -1,18 +1,18 @@
 <?php
 /**
  * by plabudda 2013-10-09:
- * 
+ *
  * 1. install:
  *   - create *.plist file:
  *     # php /Library/Server/Web/Data/Sites/Default/SE/se-dev-pl/bash_sync_perms.php biuro.biall-net.pl addToLaunchctl
  *     # php /Library/Server/Web/Data/Sites/Default/SE/bash_sync_perms.php biuro.medical-opakowania.pl addToLaunchctl
  *   - load by launchctl:
  *     # launchctl load /Library/LaunchDaemons/pl.biallnet.sync_perms.php.plist
- * 
+ *
  * 2. uninstall:
  *   - unload from launchctl:
  *     # launchctl unload /Library/LaunchDaemons/pl.biallnet.sync_perms.php.plist
- * 
+ *
  * 3. debug:
  *   - debug by www:
  *     /SE/se-dev-pl/bash_sync_perms.php?DBG=1
@@ -23,8 +23,8 @@
  *     /SE/se-dev-pl/bash_sync_perms.php?task=newFiles
  *     /SE/se-dev-pl/bash_sync_perms.php?task=testParse
  * 		 /SE/se-dev-pl/bash_sync_perms.php?task=task&PROJ_ID={projID}  -- force update project
- * 
- * 
+ *
+ *
  * 4. Sync users: `ADMIN_USERS`.`A_STATUS` - OFF - manual sync from users table (groups from CRM_LISTA_ZASOBOW)
  *   'WAITING' - Kandydaci
  *   'NORMAL' - Aktywni pracownicy
@@ -35,8 +35,8 @@
  * @2014-01 recomended by A.Binder migration to separate dirs of koresp scripts:
  * robienie katalogow dla korespondencji przy migracji na nowy typ pism
   #read PASSWORD
-  #for a in `echo "select concat(ID,';---;',K_OD_KOGO,K_ZAWARTOS) from IN7_DZIENNIK_KORESP" |mysql -p$PASSWORD -uroot -Damssystem -h127.0.0.1  | sed 's/[^a-zA-Z0-9;-]/_/g' |sed 's/;---;/\./g' ` ; 
-  #do 
+  #for a in `echo "select concat(ID,';---;',K_OD_KOGO,K_ZAWARTOS) from IN7_DZIENNIK_KORESP" |mysql -p$PASSWORD -uroot -Damssystem -h127.0.0.1  | sed 's/[^a-zA-Z0-9;-]/_/g' |sed 's/;---;/\./g' ` ;
+  #do
   #echo mkdir $a
   #mkdir $a
   #done
@@ -45,17 +45,17 @@
  # for a in `ls |awk -F'.' '{ print $1 }' ` ; do mv $a.* ../$a.*; done
  *
  *
- * 
+ *
  * DONE: koresp format: PISMA/ID/...
  * DONE: projekty -> koresp hardlink PROJEKTY/ID..../_PISMA/{HL:pismo.pdf}
  * TODO: PROJEKTY/ID..../_PISMA/ permy tylko read/listing
  * TODO: hardlink druki: mkdir DRUKI/ID.{DESC}/_PROJEKT/{proj_folder}/{HL:pliki z proj bez podkatalogów}
  * TODO: DRUKI/ID.{DESC}/_PROJEKT/{proj_folder} permy tylko read/listing
  * -- TODO: DRUKI/ID.{DESC}/ - permy z bazy danych A_ADM_COMPANY, A_CLASSIFIED
- * 
- * 
+ *
+ *
  * DONE: Trigger po update/insert Koresp po aktualizacji permów plików projektu
- * 
+ *
  * 5. Sync custom tables
  *     TEST 2014-10-27: # php /Users/plabudda/rsync-dev/SE/bash_sync_perms.php biuro.biall-net.pl SyncPermsCustomTables
  * 5.1 Table list in CRM_CONFIG(key=_SYNC_TABLE_FILE_PERMS__TablesList)
@@ -72,7 +72,7 @@ define('APP_PATH_WWW', dirname(__FILE__));
 define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');
 
 // set ini to log errors into error log file
-ini_set('display_startup_errors', '0'); 
+ini_set('display_startup_errors', '0');
 ini_set('log_errors', '1');
 ini_set('error_log', '/var/log/apache2/error_log');// TODO: php.ini ?
 
@@ -209,6 +209,247 @@ if (!empty($_SERVER["argv"][0]) && !empty($_SERVER["argv"][1])) {
 
 class SyncPerms {
 
+	public static function run($script_name, $domain, $arg2 = null, $arg3 = null) {
+		if ($arg2 == 'addToLaunchctl') self::task__addToLaunchctl($domain);
+		else if ($arg2 == 'newFiles') self::task__newFiles();
+		else if ($arg2 == 'nextTask') self::task__nextTask();
+		else if ($arg2 == 'testErrorLog') self::task__testErrorLog();
+		else if ($arg2 == 'users') self::usersAction();
+		else if ($arg2 == 'usersAll') self::usersAllAction();
+		else if ($arg2 == 'SyncPermsCustomTables') self::task__SyncPermsCustomTables();
+		else self::task__default();
+	}
+
+	public static function task__addToLaunchctl($domain) {
+		$plistFile = "/Library/LaunchDaemons/pl.biallnet.sync_perms.{$domain}.php.plist";
+		system("echo \"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
+<plist version=\"1.0\">
+<dict>
+<key>Disabled</key>
+	<false/>
+	<key>Label</key>
+	<string>pl.biallnet.sync_perms.{$domain}.php</string>
+	<key>UserName</key>
+	<string>root</string>
+	<key>ProgramArguments</key>
+	<array>
+		 <string>php</string>
+			<string>{$_SERVER["argv"][0]}</string>
+			<string>{$_SERVER["argv"][1]}</string>
+	</array>
+	<key>StartInterval</key>
+	<integer>60</integer>
+</dict>
+</plist>
+
+\" > {$plistFile}");
+		echo "Run as root: launchctl load {$plistFile} \n";
+	}
+
+	public static function task__newFiles() {
+		$time = new stdClass();
+		$time->start = time();
+		self::newFilesAction();
+		$time->end = time();
+		// TODO: print operation time if DBG
+	}
+
+	public static function task__nextTask() {
+		$time = new stdClass();
+		$time->start = time();
+
+		if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:2px solid red;text-align:left;">nextTask</pre>';}
+		self::installTable();
+		if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:2px solid red;text-align:left;">installTable DONE</pre>';}
+		self::generateTasksNewRecords();
+		if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:2px solid red;text-align:left;">generateTasksNewRecords DONE</pre>';}
+		self::generateTasksUpdated();
+		if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:2px solid red;text-align:left;">generateTasksUpdated DONE</pre>';}
+
+		$limit = V::get('_limit', 1, $_GET, 'int');
+		for ($i = 0; $i < $limit; $i++) {
+			$time->cur = time();
+			if ($time->cur - $time->start > 60 * 5) {
+				if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:2px solid red;text-align:left;">Force-break time('.($time->cur - $time->start).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';echo'</pre>';}
+				break;
+			}
+
+			$task = self::nextTaskAction();
+			if (!$task) break;
+		}
+	}
+
+	public static function task__testErrorLog() {
+		echo "display_errors: " . ini_get("display_errors") . "\n";
+		echo "display_startup_errors: " . ini_get("display_startup_errors") . "\n";
+		echo "log_errors: " . ini_get("log_errors") . "\n";
+		echo "error_reporting: " . ini_get("error_reporting") . "\n";
+		echo "error_log: " . ini_get("error_log") . "\n";
+		trigger_error("Notice: Test Error Log", E_USER_NOTICE);
+	}
+
+	public static function task__SyncPermsCustomTables() {
+		$DBG_TIME = true;
+		$dbgTime = new stdClass();
+		$dbgTime->startTime = microtime(true);
+		$dbgTime->lastTime = $dbgTime->startTime;
+
+		$customSync = new SyncPermsCustomTables();
+		// TODO: $customSync->run();
+		$customSync->fetchConfig();
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			trigger_error("DBG:time after-fetchConfig (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
+		$customSync->installTable();
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			trigger_error("DBG:time after-installTable (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
+
+		$rowId = (int)$arg3;
+		if ($rowId > 0) {
+			$customSync->executeTask('DEALS_TABLE', $rowId);// TODO: DEALS_TABLE ?
+		}
+		else {
+			$customSync->generateTasksNewRecords();
+			if ($DBG_TIME) {
+				$dbgTime->curTime = microtime(true);
+				trigger_error("DBG:time after-generateTasksNewRecords (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+				$dbgTime->lastTime = $dbgTime->curTime;
+			}
+			$customSync->generateTasksUpdated();
+			if ($DBG_TIME) {
+				$dbgTime->curTime = microtime(true);
+				trigger_error("DBG:time after-generateTasksUpdated (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+				$dbgTime->lastTime = $dbgTime->curTime;
+			}
+			$customSync->newFilesAction();
+			if ($DBG_TIME) {
+				$dbgTime->curTime = microtime(true);
+				trigger_error("DBG:time after-newFilesAction (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+				$dbgTime->lastTime = $dbgTime->curTime;
+			}
+			$limit = 1000;
+			for ($i = 0; $i < $limit; $i++) {
+				$loopTasksFired = 0;
+				foreach ($customSync->_tbls as $tblName => $tblConf) {
+					$task = $customSync->nextTaskAction($tblName);
+					if ($DBG_TIME) {
+						$dbgTime->curTime = microtime(true);
+						trigger_error("DBG:time after-nextTaskAction (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+						$dbgTime->lastTime = $dbgTime->curTime;
+					}
+					if (!$task) {
+						// TODO: rm $tblName from config to prevent searching for task in next loops
+						unset($customSync->_tbls[$tblName]);
+						continue;
+					}
+					$loopTasksFired++;
+				}
+				if (!$loopTasksFired) {
+					if ($DBG_TIME) {
+						$dbgTime->curTime = microtime(true);
+						trigger_error("DBG:time after-nextTaskAction (loop:{$i}) (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+						$dbgTime->lastTime = $dbgTime->curTime;
+					}
+					break;
+				}
+				$i += $loopTasksFired;
+			}
+		}
+
+		$dbgTime->endTime = microtime(true);
+		trigger_error("Notice: sync end OK (time:" . number_format($dbgTime->endTime - $dbgTime->startTime, 6) . "s) !", E_USER_NOTICE);
+	}
+
+	public static function task__default() {
+		$DBG_TIME = false;
+		$DBG_MEMORY = false;
+		$dbgTime = new stdClass();
+		$dbgTime->start = time();
+		$dbgTime->startTime = microtime(true);
+		$dbgTime->lastTime = $dbgTime->startTime;
+
+		self::installTable();
+
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			trigger_error("DBG:time after-installTable (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
+
+		self::generateTasksNewRecords();
+
+		if($DBG_MEMORY)trigger_error("DBG:mem usage after-generateTasksNewRecords " . memory_get_usage(true) . ".", E_USER_NOTICE);
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			trigger_error("DBG:time after-generateTasksNewRecords (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
+
+		self::generateTasksUpdated();
+
+		if($DBG_MEMORY)trigger_error("DBG:mem usage after-generateTasksUpdated " . memory_get_usage(true) . ".", E_USER_NOTICE);
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			trigger_error("DBG:time after-generateTasksUpdated (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
+
+		$dbgTime->cur = time();
+		if ($dbgTime->cur - $dbgTime->start > 60 * 5) {
+			trigger_error("Error: time end after-init " . ($dbgTime->cur - $dbgTime->start) . " !", E_USER_NOTICE);
+			return;
+		}
+
+		self::newFilesAction();
+
+		if($DBG_MEMORY)trigger_error("DBG:mem usage after-newFilesAction " . memory_get_usage(true) . ".", E_USER_NOTICE);
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			trigger_error("DBG:time after-newFilesAction (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
+
+		$limit = 100;
+		for ($i = 0; $i < $limit; $i++) {
+			$dbgTime->cur = time();
+			if ($dbgTime->cur - $dbgTime->start > 60 * 5) {
+				trigger_error("Error: time end after-nextTaskAction(loop:{$i}) " . ($dbgTime->cur - $dbgTime->start) . " !", E_USER_NOTICE);
+				return;
+			}
+
+			$task = self::nextTaskAction();
+			if($DBG_MEMORY)trigger_error("DBG:mem usage after-nextTaskAction (loop:{$i}) " . memory_get_usage(true) . ".", E_USER_NOTICE);
+			if ($DBG_TIME) {
+				$dbgTime->curTime = microtime(true);
+				trigger_error("DBG:time after-nextTaskAction (loop:{$i}) (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+				$dbgTime->lastTime = $dbgTime->curTime;
+			}
+
+			if (!$task) {
+				$dbgTime->cur = time();
+				break;
+			}
+		}
+
+		$customSync = new SyncPermsCustomTables();
+		$customSync->run();
+
+		$dbgTime->cur = time();
+		$dbgTime->endTime = microtime(true);
+		trigger_error("Notice: sync end OK (time:" . number_format($dbgTime->endTime - $dbgTime->startTime, 6) . "s) !", E_USER_NOTICE);
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			trigger_error("DBG:time sync end OK (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
+	}
+
 	public static function installTable() {
 		$db = DB::getDB();
 		if (!$db) die("DB Error: No DB! L." . __LINE__);
@@ -267,253 +508,15 @@ class SyncPerms {
 		}
 	}
 
-	public static function run($script_name, $domain, $arg2 = null, $arg3 = null) {
-		if ($arg2 == 'addToLaunchctl') {
-			$plistFile = "/Library/LaunchDaemons/pl.biallnet.sync_perms.{$domain}.php.plist";
-			system("echo \"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
-<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
-<plist version=\"1.0\">
-<dict>
-	<key>Disabled</key>
-		<false/>  
-		<key>Label</key>
-		<string>pl.biallnet.sync_perms.{$domain}.php</string>
-		<key>UserName</key>
-		<string>root</string>
-		<key>ProgramArguments</key>
-		<array>
-			 <string>php</string>
-				<string>{$_SERVER["argv"][0]}</string>
-				<string>{$_SERVER["argv"][1]}</string>
-		</array>
-		<key>StartInterval</key>
-		<integer>60</integer>
-</dict>
-</plist>
-
-\" > {$plistFile}");
-			echo "Run as root: launchctl load {$plistFile} \n";
-		}
-		else if ($arg2 == 'newFiles') {
-			$time = new stdClass();
-			$time->start = time();
-			self::newFilesAction();
-			$time->end = time();
-			// TODO: print operation time if DBG
-		}
-		else if ($arg2 == 'nextTask') {
-			$time = new stdClass();
-			$time->start = time();
-
-			if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:2px solid red;text-align:left;">nextTask</pre>';}
-			self::installTable();
-			if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:2px solid red;text-align:left;">installTable DONE</pre>';}
-			self::generateTasksNewRecords();
-			if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:2px solid red;text-align:left;">generateTasksNewRecords DONE</pre>';}
-			self::generateTasksUpdated();
-			if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:2px solid red;text-align:left;">generateTasksUpdated DONE</pre>';}
-
-			$limit = V::get('_limit', 1, $_GET, 'int');
-			for ($i = 0; $i < $limit; $i++) {
-				$time->cur = time();
-				if ($time->cur - $time->start > 60 * 5) {
-					if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:2px solid red;text-align:left;">Force-break time('.($time->cur - $time->start).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';echo'</pre>';}
-					break;
-				}
-
-				$task = self::nextTaskAction();
-				if (!$task) {
-					break;
-				}
-			}
-		}
-		else if ($arg2 == 'testErrorLog') {
-			echo "display_errors: " . ini_get("display_errors") . "\n";
-			echo "display_startup_errors: " . ini_get("display_startup_errors") . "\n";
-			echo "log_errors: " . ini_get("log_errors") . "\n";
-			echo "error_reporting: " . ini_get("error_reporting") . "\n";
-			echo "error_log: " . ini_get("error_log") . "\n";
-			trigger_error("Notice: Test Error Log", E_USER_NOTICE);
-		}
-		else if ($arg2 == 'users') {
-			self::usersAction();
-		}
-		else if ($arg2 == 'usersAll') {
-			self::usersAllAction();
-		}
-		else if ($arg2 == 'SyncPermsCustomTables') {
-			$DBG_TIME = true;
-			$dbgTime = new stdClass();
-			$dbgTime->startTime = microtime(true);
-			$dbgTime->lastTime = $dbgTime->startTime;
-
-			$customSync = new SyncPermsCustomTables();
-			// TODO: $customSync->run();
-			$customSync->fetchConfig();
-			if ($DBG_TIME) {
-				$dbgTime->curTime = microtime(true);
-				trigger_error("DBG:time after-fetchConfig (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-				$dbgTime->lastTime = $dbgTime->curTime;
-			}
-			$customSync->installTable();
-			if ($DBG_TIME) {
-				$dbgTime->curTime = microtime(true);
-				trigger_error("DBG:time after-installTable (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-				$dbgTime->lastTime = $dbgTime->curTime;
-			}
-
-			$rowId = (int)$arg3;
-			if ($rowId > 0) {
-				$customSync->executeTask('DEALS_TABLE', $rowId);
-			}
-			else {
-				$customSync->generateTasksNewRecords();
-				if ($DBG_TIME) {
-					$dbgTime->curTime = microtime(true);
-					trigger_error("DBG:time after-generateTasksNewRecords (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-					$dbgTime->lastTime = $dbgTime->curTime;
-				}
-				$customSync->generateTasksUpdated();
-				if ($DBG_TIME) {
-					$dbgTime->curTime = microtime(true);
-					trigger_error("DBG:time after-generateTasksUpdated (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-					$dbgTime->lastTime = $dbgTime->curTime;
-				}
-				$customSync->newFilesAction();
-				if ($DBG_TIME) {
-					$dbgTime->curTime = microtime(true);
-					trigger_error("DBG:time after-newFilesAction (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-					$dbgTime->lastTime = $dbgTime->curTime;
-				}
-				$limit = 1000;
-				for ($i = 0; $i < $limit; $i++) {
-					$loopTasksFired = 0;
-					foreach ($customSync->_tbls as $tblName => $tblConf) {
-						$task = $customSync->nextTaskAction($tblName);
-						if ($DBG_TIME) {
-							$dbgTime->curTime = microtime(true);
-							trigger_error("DBG:time after-nextTaskAction (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-							$dbgTime->lastTime = $dbgTime->curTime;
-						}
-						if (!$task) {
-							// TODO: rm $tblName from config to prevent searching for task in next loops
-							unset($customSync->_tbls[$tblName]);
-							continue;
-						}
-						$loopTasksFired++;
-					}
-					if (!$loopTasksFired) {
-						if ($DBG_TIME) {
-							$dbgTime->curTime = microtime(true);
-							trigger_error("DBG:time after-nextTaskAction (loop:{$i}) (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-							$dbgTime->lastTime = $dbgTime->curTime;
-						}
-						break;
-					}
-					$i += $loopTasksFired;
-				}
-			}
-
-			$dbgTime->endTime = microtime(true);
-			trigger_error("Notice: sync end OK (time:" . number_format($dbgTime->endTime - $dbgTime->startTime, 6) . "s) !", E_USER_NOTICE);
-		}
-		else {
-			$DBG_TIME = false;
-			$DBG_MEMORY = false;
-			$dbgTime = new stdClass();
-			$dbgTime->start = time();
-			$dbgTime->startTime = microtime(true);
-			$dbgTime->lastTime = $dbgTime->startTime;
-
-			self::installTable();
-
-			if ($DBG_TIME) {
-				$dbgTime->curTime = microtime(true);
-				trigger_error("DBG:time after-installTable (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-				$dbgTime->lastTime = $dbgTime->curTime;
-			}
-
-			self::generateTasksNewRecords();
-
-			if($DBG_MEMORY)trigger_error("DBG:mem usage after-generateTasksNewRecords " . memory_get_usage(true) . ".", E_USER_NOTICE);
-			if ($DBG_TIME) {
-				$dbgTime->curTime = microtime(true);
-				trigger_error("DBG:time after-generateTasksNewRecords (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-				$dbgTime->lastTime = $dbgTime->curTime;
-			}
-
-			self::generateTasksUpdated();
-
-			if($DBG_MEMORY)trigger_error("DBG:mem usage after-generateTasksUpdated " . memory_get_usage(true) . ".", E_USER_NOTICE);
-			if ($DBG_TIME) {
-				$dbgTime->curTime = microtime(true);
-				trigger_error("DBG:time after-generateTasksUpdated (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-				$dbgTime->lastTime = $dbgTime->curTime;
-			}
-
-			$dbgTime->cur = time();
-			if ($dbgTime->cur - $dbgTime->start > 60 * 5) {
-				trigger_error("Error: time end after-init " . ($dbgTime->cur - $dbgTime->start) . " !", E_USER_NOTICE);
-				return;
-			}
-
-			self::newFilesAction();
-
-			if($DBG_MEMORY)trigger_error("DBG:mem usage after-newFilesAction " . memory_get_usage(true) . ".", E_USER_NOTICE);
-			if ($DBG_TIME) {
-				$dbgTime->curTime = microtime(true);
-				trigger_error("DBG:time after-newFilesAction (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-				$dbgTime->lastTime = $dbgTime->curTime;
-			}
-
-			$limit = 100;
-			for ($i = 0; $i < $limit; $i++) {
-				$dbgTime->cur = time();
-				if ($dbgTime->cur - $dbgTime->start > 60 * 5) {
-					trigger_error("Error: time end after-nextTaskAction(loop:{$i}) " . ($dbgTime->cur - $dbgTime->start) . " !", E_USER_NOTICE);
-					return;
-				}
-
-				$task = self::nextTaskAction();
-				if($DBG_MEMORY)trigger_error("DBG:mem usage after-nextTaskAction (loop:{$i}) " . memory_get_usage(true) . ".", E_USER_NOTICE);
-				if ($DBG_TIME) {
-					$dbgTime->curTime = microtime(true);
-					trigger_error("DBG:time after-nextTaskAction (loop:{$i}) (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-					$dbgTime->lastTime = $dbgTime->curTime;
-				}
-
-				if (!$task) {
-					$dbgTime->cur = time();
-					break;
-				}
-			}
-
-			$customSync = new SyncPermsCustomTables();
-			$customSync->run();
-
-			$dbgTime->cur = time();
-			$dbgTime->endTime = microtime(true);
-			trigger_error("Notice: sync end OK (time:" . number_format($dbgTime->endTime - $dbgTime->startTime, 6) . "s) !", E_USER_NOTICE);
-			if ($DBG_TIME) {
-				$dbgTime->curTime = microtime(true);
-				trigger_error("DBG:time sync end OK (time:" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s)", E_USER_NOTICE);
-				$dbgTime->lastTime = $dbgTime->curTime;
-			}
-		}
-	}
-
 	public static function newFilesAction() {
 		$task = self::getTaskNewFiles();
-
 		$taskResult = self::fixLastModifiedFiles($task);
 		self::saveTask(-1);
 	}
 
 	public static function nextTaskAction() {
 		$task = self::getTask();
-		if (!$task) {
-			return false;
-		}
+		if (!$task) return false;
 		self::executeTask($task);
 
 		/*
@@ -533,7 +536,7 @@ 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`
@@ -769,9 +772,7 @@ class SyncPerms {
 		if (!is_array($activeLoginList)) {
 			$activeLoginList = array();
 			$db = DB::getDB();
-			if (!$db) {
-				die('DB Error!');
-			}
+			if (!$db) die("DB Error: No DB! L." . __LINE__);
 			$sql = "select u.`ADM_ACCOUNT`
 				from `ADMIN_USERS` as u
 				where u.`A_STATUS` =  'NORMAL'
@@ -838,7 +839,7 @@ class SyncPerms {
 
 	/**
 	 * Used for files added/modified by samba/afp.
-	 * 
+	 *
 	 * @return TODO: object to store in task->A_SYNC_RESULT
 	 */
 	public static function fixLastModifiedFiles($task) {
@@ -853,7 +854,7 @@ class SyncPerms {
 		$foundProjectFiles = array();
 		if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$lastRunDate (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($task->A_LAST_SYNC);echo'</pre>';}
 		//exec("cd {$PROJ_mount_point}; find . -newermt '{$task->A_LAST_SYNC}' ", $foundPaths);
-		exec("cd {$PROJ_mount_point}; find . -newermt '{$task->A_LAST_SYNC}' -type f -exec ls -le '{}' \;", $filesWithPerms);// TODO: head -{$lastTotal + 10000}| tail 
+		exec("cd {$PROJ_mount_point}; find . -newermt '{$task->A_LAST_SYNC}' -type f -exec ls -le '{}' \;", $filesWithPerms);// TODO: head -{$lastTotal + 10000}| tail
 		if (!empty($filesWithPerms)) {
 			$filesWithPermsTree = array();
 			$lastName = '';
@@ -1338,13 +1339,13 @@ R		list,         search,                              readattr,          readext
 					or modification time (X=m) than the last access time (Y=a), inode creation time (Y=B), change time (Y=c), or mod-
 					ification time (Y=m) of file.  In addition, if Y=t, then file is instead interpreted as a direct date specifica-
 					tion of the form understood by cvs(1).  Note that -newermm is equivalent to -newer.
-		 * 
+		 *
 		 * $ man chmod:
 			 -i      Removes the 'inherited' bit from all entries in the named file(s) ACLs.
 		 *
 		 * chmod -a "admin allow write" file1  # remove line
 		 * chmod -a# 1 file1                   # remove line at position 1
-		 * 
+		 *
 		 * chmod +a nie zmienia modify date: find . -newermt '2013-10-07 ...'
 		 */
 		// find /Library/Server/Web/Data/Sites/Default/PLIKI/PROJEKTY -newermt '2013-10-07 16:20'
@@ -1468,19 +1469,19 @@ R		list,         search,                              readattr,          readext
 		/*
 		 * DBU - DB User       LDU - LDAP User
 		 * DBG - DB Group      LDG - LDAP Group
-		 * 
+		 *
 		 * DBU - ADMIN_USERS
 		 * DBG - CRM_LISTA_ZASOBOW where TYPE in('STANOWISKO','PODMIOT','DZIAL')// TODO: GRUPA_PROJEKTOWA - ldap nested group?
-		 * 
+		 *
 		 * 1. fetch DB Users
 		 *   ? only active users (A_STATUS == 'NORMAL')
 		 * 2. fetch LDAP Users
-		 * 
+		 *
 		 * DBU.ADM_ACCOUNT == LDU.uid
 		 * DBG.A_LDAP_GID == LDG.gidNumber
-		 * 
+		 *
 		 * TODO: $group createLdapGroup()
-		 * 
+		 *
 		 */
 		Lib::loadClass('UsersHelper');
 		$users = self::getUsersAll();
@@ -1492,7 +1493,7 @@ R		list,         search,                              readattr,          readext
 		}
 		unset($allLdapUsers);
 		echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">ldapUsers count('.count($ldapUsers).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($ldapUsers);echo'</pre>';
-		
+
 		foreach ($users as $kLogin => $vUser) {
 			if ($vUser->A_STATUS == 'NORMAL') {
 				if (array_key_exists($vUser->ADM_ACCOUNT, $ldapUsers)) {
@@ -1773,7 +1774,7 @@ class SyncPermsCustomTables {
 		//exec("cd {$TBL_mount_point}; find . -newermt '{$task->A_LAST_SYNC}' ", $foundPaths);
 		$filesWithPerms = array();
 		$cmd = "cd {$TBL_mount_point}; find . -newermt '{$task->A_LAST_SYNC}' -type f -exec ls -le '{}' \;";
-		exec($cmd, $filesWithPerms);// TODO: head -{$lastTotal + 10000}| tail 
+		exec($cmd, $filesWithPerms);// TODO: head -{$lastTotal + 10000}| tail
 		if (!empty($filesWithPerms)) {
 			$filesWithPermsTree = array();
 			$lastName = '';
@@ -2046,7 +2047,7 @@ class SyncPermsCustomTables {
 	}
 
 	public function _fetchActiveLoginList() {
-		if (!$this->_db) die('DB Error!');
+		if (!$this->_db) die("DB Error: No DB! L." . __LINE__);
 		if (!is_array($this->_activeLoginList)) {
 			$this->_activeLoginList = array();
 			$sql = "select u.`ADM_ACCOUNT`
@@ -2186,10 +2187,10 @@ class SyncPermsCustomTables {
 	private function _executeTask($task) {
 		if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">executeTask (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($task);echo'</pre>';}
 
-$DBG_TIME = false;
-$dbgTime = new stdClass();
-$dbgTime->startTime = microtime(true);
-$dbgTime->lastTime = $dbgTime->startTime;
+		$DBG_TIME = false;
+		$dbgTime = new stdClass();
+		$dbgTime->startTime = microtime(true);
+		$dbgTime->lastTime = $dbgTime->startTime;
 
 		$confTblName = "{$task->TBL_NAME}_COLUMN";
 		$TBL_mount_point = FoldersConfig::get($confTblName, 'mount_point');
@@ -2204,20 +2205,20 @@ $dbgTime->lastTime = $dbgTime->startTime;
 			die("Error: folders config!");
 		}
 
-if ($DBG_TIME) {
-	$dbgTime->curTime = microtime(true);
-	echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):" . __LINE__ . ":_executeTask({$task->TBL_NAME}/{$task->TBL_ID}]: after-FileUploader->setConfig" . "\n";
-	$dbgTime->lastTime = $dbgTime->curTime;
-}
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):" . __LINE__ . ":_executeTask({$task->TBL_NAME}/{$task->TBL_ID}]: after-FileUploader->setConfig" . "\n";
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
 
 		$uploader->findFolder();
 		$mainFolder = $uploader->getDestFolder();
 
-if ($DBG_TIME) {
-	$dbgTime->curTime = microtime(true);
-	echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):" . __LINE__ . ":_executeTask({$task->TBL_NAME}/{$task->TBL_ID}]:time after-FileUploader->getDestFolder" . "\n";
-	$dbgTime->lastTime = $dbgTime->curTime;
-}
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):" . __LINE__ . ":_executeTask({$task->TBL_NAME}/{$task->TBL_ID}]:time after-FileUploader->getDestFolder" . "\n";
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
 
 		if(V::get('DBG', '', $_GET, 'int') > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">generated folderName('.$record->ID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';var_dump($uploader);echo'</pre>';}
 		if (!$mainFolder) {
@@ -2247,11 +2248,11 @@ if ($DBG_TIME) {
 			$cmdList = $this->_fixRecord($record, $uploader, $mainFolder, $TBL_mount_point, $task);
 		}
 
-if ($DBG_TIME) {
-	$dbgTime->curTime = microtime(true);
-	echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):" . __LINE__ . ":_executeTask({$task->TBL_NAME}/{$task->TBL_ID}]: after-generate cmdList - mainFolder(" . (($mainFolder)? 1 : 0) . ")" . "\n";
-	$dbgTime->lastTime = $dbgTime->curTime;
-}
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):" . __LINE__ . ":_executeTask({$task->TBL_NAME}/{$task->TBL_ID}]: after-generate cmdList - mainFolder(" . (($mainFolder)? 1 : 0) . ")" . "\n";
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
 
 		if (!empty($cmdList)) {
 			foreach ($cmdList as $vCmd) {
@@ -2266,11 +2267,11 @@ if ($DBG_TIME) {
 			}
 		}
 
-if ($DBG_TIME) {
-	$dbgTime->curTime = microtime(true);
-	echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):" . __LINE__ . ":_executeTask({$task->TBL_NAME}/{$task->TBL_ID}]: after-executed cmdList " . "\n";
-	$dbgTime->lastTime = $dbgTime->curTime;
-}
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):" . __LINE__ . ":_executeTask({$task->TBL_NAME}/{$task->TBL_ID}]: after-executed cmdList " . "\n";
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
 
 		if(V::get('DBG', '', $_GET, 'int') > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">';print_r("executeTask finished OK");echo'</pre>';}
 	}
@@ -2296,14 +2297,13 @@ if ($DBG_TIME) {
 			exec($cmd, $filesWithPerms);
 		}
 
-//echo "\n-----------------------\n";
-//echo "filesWithPerms: ";print_r($filesWithPerms);echo "\n";
-
-if ($DBG_TIME) {
-	$dbgTime->curTime = microtime(true);
-	echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):_fixRecord: cd '{$TBL_mount_point}/{$mainFolder}' && {$cmd} " . "\n";
-	$dbgTime->lastTime = $dbgTime->curTime;
-}
+		//echo "\n-----------------------\n";
+		//echo "filesWithPerms: ";print_r($filesWithPerms);echo "\n";
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):_fixRecord: cd '{$TBL_mount_point}/{$mainFolder}' && {$cmd} " . "\n";
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
 
 		$filesWithPermsTree = array();
 		$lastName = '';
@@ -2367,13 +2367,12 @@ if ($DBG_TIME) {
 			}
 		}
 
-//echo "filesWithPermsTree: ";print_r($filesWithPermsTree);echo "\n";
-
-if ($DBG_TIME) {
-	$dbgTime->curTime = microtime(true);
-	echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):_fixRecord: parse cmd output" . "\n";
-	$dbgTime->lastTime = $dbgTime->curTime;
-}
+		//echo "filesWithPermsTree: ";print_r($filesWithPermsTree);echo "\n";
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):_fixRecord: parse cmd output" . "\n";
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
 
 		if(V::get('DBG', '', $_GET, 'int') > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$filesWithPermsTree (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($filesWithPermsTree);echo'</pre>';}
 
@@ -2404,14 +2403,13 @@ R		list,         search,                              readattr,          readext
 				}
 			}
 		}
-//echo "cmdList: ";print_r($cmdList);echo "\n";
-//echo "\n-----------------------\n";
-
-if ($DBG_TIME) {
-	$dbgTime->curTime = microtime(true);
-	echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):_fixRecord: end" . "\n";
-	$dbgTime->lastTime = $dbgTime->curTime;
-}
+		//echo "cmdList: ";print_r($cmdList);echo "\n";
+		//echo "\n-----------------------\n";
+		if ($DBG_TIME) {
+			$dbgTime->curTime = microtime(true);
+			echo "DBG:(" . number_format($dbgTime->curTime - $dbgTime->lastTime, 6) . "s):_fixRecord: end" . "\n";
+			$dbgTime->lastTime = $dbgTime->curTime;
+		}
 
 		return $cmdList;
 	}