Sfoglia il codice sorgente

added update acl cache to Status

Piotr Labudda 8 anni fa
parent
commit
e95b26ca9d

+ 53 - 10
SE/se-lib/Route/Status.php

@@ -3,6 +3,7 @@
 Lib::loadClass('RouteBase');
 Lib::loadClass('UI');
 Lib::loadClass('Response');
+Lib::loadClass('SchemaFactory');
 
 class Route_Status extends RouteBase {
 
@@ -17,6 +18,20 @@ class Route_Status extends RouteBase {
 		try {
 			DB::getPDO();
 
+			if ($postTask = V::get('_postTask', '', $_REQUEST)) {
+				DBG::log($args, 'array', "exec '{$postTask}'");
+				if (!method_exists($this, "{$postTask}PostTask")) throw new Exception("Post Task not exists!");
+				ob_start();
+				$this->{"{$postTask}PostTask"}($args);
+				$outputPostTask = ob_get_clean();
+				if ($outputPostTask) {
+					echo UI::h('details', [], [
+						UI::h('summary', [], "Wynik '{$postTask}' <i>(rozwiń)</i>"),
+						$outputPostTask,
+					]);
+				}
+			}
+
 			$this->viewStatusDatabase();
 
 			if (in_array(User::get('ADM_ADMIN_LEVEL'), ['0', '1'])) {
@@ -35,36 +50,64 @@ class Route_Status extends RouteBase {
 	}
 
 	public function viewStatusDatabase() {
-		if (1 == V::get('event_sheduler_on', '', $_POST)) {
-			$this->fixEventSheduler();
-		}
-
 		$dbEvents = DB::getPDO()->fetchFirst(" SHOW VARIABLES WHERE VARIABLE_NAME = 'event_scheduler' ");
 		// DBG::nicePrint($dbEvents, '$dbEvents');
 		//	 [Variable_name] => event_scheduler
 		//	 [Value] => ON
 
+		$aclObjectCacheExists = false;
+		$objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
+		$aclCacheTableName = $objectStorage->getRootTableName();
+		if ($aclCacheTableName) {
+			try {
+				$totalObjects = DB::getPDO()->fetchValue("select count(*) as cnt from `{$aclCacheTableName}`");
+				if ($totalObjects > 0) $aclObjectCacheExists = true;
+			} catch (Exception $e) {
+				DBG::log($e);
+			}
+		}
+		DBG::log($objectStorage, 'array', "\$objectStorage");
+		DBG::log($objectStorage->getRootTableName(), 'array', "\$objectStorage->getRootTableName()");
+
 		UI::table([
 			'caption' => UI::h('b', ['style' => "color:#000"], 'Baza danych'),
 			'rows' => [
 				[
-					'nazwa' => 'Event Scheduler (generowanie Grafika, itp.)',
+					'nazwa' => "Event Scheduler (generowanie Grafika, itp.)",
 					'wartość' => ('ON' == $dbEvents['Value'])
-					? UI::h('span', ['class' => "label label-success"], "ON")
-					: UI::h('span', ['class' => "label label-danger"], "OFF"),
+					?	UI::h('span', ['class' => "label label-success"], "ON")
+					:	UI::h('span', ['class' => "label label-danger"], "OFF"),
 					'#' => UI::hButtonPost("Włącz", [
 						'class' => "btn btn-xs btn-default",
 						'data' => [
-							'event_sheduler_on' => 1
+							'_postTask' => 'fixEventSheduler',
 						]
 					])
-				]
+				],
+				[
+					'nazwa' => "System obiektów (xsd)",
+					'wartość' => ($aclObjectCacheExists)
+					?	UI::h('span', ['class' => "label label-success"], "ON")
+					:	UI::h('span', ['class' => "label label-danger"], "OFF"),
+					'#' => UI::hButtonPost("Aktualizuj cache", [
+						'class' => "btn btn-xs btn-default",
+						'data' => [
+							'_postTask' => 'updateObjectCache'
+						]
+					])
+				],
 			]
 		]);
 	}
-	public function fixEventSheduler() {
+	public function fixEventShedulerPostTask() {
 		DB::getPDO()->execSql(" SET GLOBAL event_scheduler='ON' ");
 	}
+	public function updateObjectCachePostTask() {
+		DBG::log("updateObjectCachePostTask...");
+		SchemaFactory::loadDefaultObject('SystemObject')->updateCache();
+		SchemaFactory::loadDefaultObject('SystemObjectField')->updateCache();
+		UI::alert('info', "Lista obiketów zaktualizowana");
+	}
 
 	public function viewStatusUsers() {
 		$nowMinus3Months = date("Y-m-d", mktime(0,0,0, date('m') - 1, date('d'), date('Y')));

+ 3 - 0
SE/se-lib/Schema/SystemObjectFieldStorageAcl.php

@@ -82,6 +82,9 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
         KEY `isActive` (isActive)
       ) ENGINE=MyISAM  DEFAULT CHARSET=latin2
     ");
+
+	if (!$namespace) return;
+
     DB::getPDO()->update($this->_rootTableName, 'objectNamespace', $namespace, ['isActive' => 0]);
     DB::getPDO()->update("{$this->_rootTableName}_enum", 'objectNamespace', $namespace, ['isActive' => 0]);
     $sysObjectStorage = SchemaFactory::loadDefaultObject('SystemObject');