Kaynağa Gözat

updated remove field from trash in Storage Struct

Piotr Labudda 8 yıl önce
ebeveyn
işleme
75837d57e9
1 değiştirilmiş dosya ile 72 ekleme ve 6 silme
  1. 72 6
      SE/se-lib/Route/Storage/AclStruct.php

+ 72 - 6
SE/se-lib/Route/Storage/AclStruct.php

@@ -881,6 +881,7 @@ class Route_Storage_AclStruct extends RouteBase {
 						UI::h('tr', [], [
 							UI::h('th', [], "#"),
 							UI::h('th', [], "namespace"),
+							UI::h('th', [], "idZasob"),
 							UI::h('th', [], "xsdType"),
 							UI::h('th', [], "xsdRestrictions"),
 							UI::h('th', [], "appInfo"),
@@ -902,6 +903,11 @@ class Route_Storage_AclStruct extends RouteBase {
 								])
 							]),
 							UI::h('td', [], $field['fieldNamespace']),
+							UI::h('td', [], [
+								($field['idZasob'] > 0)
+								? UI::h('span', [ 'class' => 'text-danger', 'title' => "Zasób zostanie usunięty" ], "{$field['idZasob']}")
+								: UI::h('span', [ 'class' => 'text-muted' ], "brak")
+							]),
 							UI::h('td', [], $field['xsdType']),
 							UI::h('td', [], $field['xsdRestrictions']),
 							UI::h('td', [], $field['appInfo']),
@@ -1106,12 +1112,26 @@ class Route_Storage_AclStruct extends RouteBase {
 		$fieldItem = SchemaFactory::loadDefaultObject('SystemObjectField')->getItem($fieldNamespace);
 		if (!$fieldItem) throw new HttpException("Field not found '{$fieldNamespace}'", 404);
 		DBG::log($fieldItem, 'array', "\$fieldItem");
-		switch ($fieldItem['xsdType']) {
-			case 'p5:enum': throw new Exception("TODO: remove enum values first"); break; // CRM_#CACHE_ACL_OBJECT_FIELD_enum
-			default: {
-				if ('ref:' === substr($fieldItem['xsdType'], 0, 4)) { // OK, remove
-				} else throw new Exception("TODO: remove xsdType: {$fieldItem['xsdType']}");
-			}
+
+		if ('p5:enum' === $fieldItem['xsdType']) {
+			// DBG::log(DB::getPDO()->fetchAll("
+			// 	select e.*
+			// 	from `CRM_#CACHE_ACL_OBJECT_FIELD_enum` e
+			// 	where e.objectNamespace = :objectNamespace
+			// 		and e.fieldNamespace = :fieldNamespace
+			// ", [
+			// 	':objectNamespace' => $fieldItem['objectNamespace'],
+			// 	':fieldNamespace' => $fieldItem['fieldNamespace'],
+			// ]), 'array', "enum values");
+			DB::getPDO()->execSql("
+				DELETE from `CRM_#CACHE_ACL_OBJECT_FIELD_enum`
+				where objectNamespace = :objectNamespace
+					and fieldNamespace = :fieldNamespace
+					and isActive = 0
+			", [
+				':objectNamespace' => $fieldItem['objectNamespace'],
+				':fieldNamespace' => $fieldItem['fieldNamespace'],
+			]);
 		}
 
 		DB::getPDO()->execSql("
@@ -1126,6 +1146,52 @@ class Route_Storage_AclStruct extends RouteBase {
 			'objectNamespace' => $fieldItem['objectNamespace'],
 			'rootTableName' => $fieldItem['_rootTableName'],
 		]);
+
+		if ($fieldItem['idZasob'] > 0) {
+			$zasob = DB::getPDO()->fetchFirst(" select z.ID, z.A_STATUS, z.DESC from CRM_LISTA_ZASOBOW z where z.ID = :id ", [ ':id' => $fieldItem['idZasob'] ]);
+			if ($zasob) {
+				if ('DELETED' !== $zasob['A_STATUS']) {
+					$affected = DB::getPDO()->update('CRM_LISTA_ZASOBOW', 'ID', $zasob['ID'], [
+						'A_STATUS' => 'DELETED',
+						'A_RECORD_UPDATE_DATE' => 'NOW()',
+						'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
+					]);
+					if ($affected) {
+						DB::getPDO()->insert('CRM_LISTA_ZASOBOW_HIST', [
+							'ID_USERS2' => $zasob['ID'],
+							'A_STATUS' => 'DELETED',
+							'A_RECORD_CREATE_DATE' => 'NOW()',
+							'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
+						]);
+					}
+				}
+			}
+			$wskazniki = DB::getPDO()->fetchAll("
+				select w.ID, w.A_STATUS
+				from CRM_WSKAZNIK w
+				where w.ID_ZASOB = :id
+			", [ ':id' => $fieldItem['idZasob'] ]);
+			if (!empty($wskazniki)) {
+				foreach ($wskazniki as $wsk) {
+					if ('DELETED' !== $wsk['A_STATUS']) {
+						$affected = DB::getPDO()->update('CRM_WSKAZNIK', 'ID', $wsk['ID'], [
+							'A_STATUS' => 'DELETED',
+							'A_RECORD_UPDATE_DATE' => 'NOW()',
+							'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
+						]);
+						if ($affected) {
+							DB::getPDO()->insert('CRM_WSKAZNIK_HIST', [
+								'ID_USERS2' => $wsk['ID'],
+								'A_STATUS' => 'DELETED',
+								'A_RECORD_CREATE_DATE' => 'NOW()',
+								'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
+							]);
+						}
+					}
+				}
+			}
+		}
+
 		return [
 			'type' => "success",
 			'msg' => "Usunięto pole {$fieldItem['fieldNamespace']}",