|
|
@@ -5,8 +5,31 @@ Lib::loadClass('RouteBase');
|
|
|
class Route_FixProjectPath extends RouteBase {
|
|
|
|
|
|
public function defaultAction() {
|
|
|
- echo 'TODO: F.' . __FUNCTION__;
|
|
|
//$sqlList['Check'] = "SHOW PROCEDURE STATUS where `Name`='update_project_path_idx_rec'";
|
|
|
+ SE_Layout::gora();
|
|
|
+ //echo '<a href="/index.php?_route=FixProjectPath&_task=run">Zaktualizuj ścieżki projektów</a>';
|
|
|
+ ?>
|
|
|
+<div class="jumbotron">
|
|
|
+ <div class="container">
|
|
|
+ <form class="form-inline" method="POST">
|
|
|
+ <input type="hidden" name="_route" value="FixProjectPath" />
|
|
|
+ <input type="hidden" name="_task" value="run" />
|
|
|
+ <button type="submit" id="fldExecuteBtn" class="btn btn-primary" autocomplete="off">
|
|
|
+ Zaktualizuj ścieżki projektów
|
|
|
+ </button>
|
|
|
+ </form>
|
|
|
+ </div>
|
|
|
+</div>
|
|
|
+<script type="text/javascript">
|
|
|
+jQuery(document).ready(function () {
|
|
|
+ jQuery('#fldExecuteBtn').on('click', function () {
|
|
|
+ jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
|
|
|
+ jQuery(this).parent().submit();
|
|
|
+ })
|
|
|
+});
|
|
|
+</script>
|
|
|
+ <?php
|
|
|
+ SE_Layout::dol();
|
|
|
}
|
|
|
|
|
|
public function checkPathsAction() {
|
|
|
@@ -48,6 +71,34 @@ class Route_FixProjectPath extends RouteBase {
|
|
|
if ($db->has_errors()) {
|
|
|
throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
|
|
|
}
|
|
|
+
|
|
|
+ SE_Layout::gora();
|
|
|
+ SE_Layout::menu();
|
|
|
+ ?>
|
|
|
+ <div class="container">
|
|
|
+ <div class="alert alert-success">
|
|
|
+ Zaktualizowano ścieżki projektów
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <?php
|
|
|
+ SE_Layout::dol();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function cleanAllPathsAction() {
|
|
|
+ $sqlList = array();
|
|
|
+ $sqlList['CleanPath_Projekty'] = "update `IN7_MK_BAZA_DYSTRYBUCJI` p set p.`path`='' ";
|
|
|
+ $sqlList['CleanPath_Koresp'] = "update `IN7_DZIENNIK_KORESP` k set k.`path`='' ";
|
|
|
+ $sqlList['CleanPath_Problems'] = "update `PROBLEMS` pr set pr.`path`='' ";
|
|
|
+ $db = DB::getDB();
|
|
|
+ if ($db->has_errors()) {
|
|
|
+ throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
|
|
|
+ }
|
|
|
+ foreach ($sqlList as $sqlName => $sql) {
|
|
|
+ $res = $db->query($sql);
|
|
|
+ if ($db->has_errors()) {
|
|
|
+ throw new Exception("DB Errors at sql '{$sqlName}': " . implode("\n<br>", $db->get_errors()));
|
|
|
+ }
|
|
|
+ }
|
|
|
die('OK');
|
|
|
}
|
|
|
|
|
|
@@ -94,6 +145,14 @@ class Route_FixProjectPath extends RouteBase {
|
|
|
SET @pinitCnt = ROW_COUNT();
|
|
|
SET @i = @i + 1;
|
|
|
END WHILE;
|
|
|
+
|
|
|
+ update `IN7_MK_BAZA_DYSTRYBUCJI` p join `_project_path_idx` i on(i.`ID`=p.`ID`)
|
|
|
+ set p.`path`=i.`idx_PATH`;
|
|
|
+ update `IN7_DZIENNIK_KORESP` k join `_project_path_idx` i on(i.`ID`=k.`ID_PROJECT`)
|
|
|
+ set k.`path`=i.`idx_PATH`;
|
|
|
+ -- TODO: update `PROBLEMS` if exists
|
|
|
+ update `PROBLEMS` pr join `_project_path_idx` i on(i.`ID`=pr.`ID_PROJECT`)
|
|
|
+ set pr.`ID_PROJECT_path`=i.`idx_PATH`;
|
|
|
END ;
|
|
|
";
|
|
|
$sqlList['RemoveTrigger_BeforeInsertProject'] = "DROP TRIGGER IF EXISTS `_IN7_MK_BAZA_DYSTRYBUCJI_tree_INSERT`";
|
|
|
@@ -113,6 +172,95 @@ class Route_FixProjectPath extends RouteBase {
|
|
|
));
|
|
|
END
|
|
|
";
|
|
|
+ $sqlList['RemoveTrigger_BeforeUpdateProject'] = "DROP TRIGGER IF EXISTS `_IN7_MK_BAZA_DYSTRYBUCJI_tree_UPDATE`";
|
|
|
+ // throws errors:
|
|
|
+ // #1146 - Table '{DATABASE_NAME}.ERROR: Loop detected ID=P_ID' doesn't exist
|
|
|
+ // #1146 - Table '{DATABASE_NAME}.ERROR: Parent item not exists' doesn't exist
|
|
|
+ // #1146 - Table '{DATABASE_NAME}.ERROR: Loop detected in path' doesn't exist
|
|
|
+ $sqlList['CreateTrigger_BeforeUpdateProject'] = "
|
|
|
+ CREATE TRIGGER `_IN7_MK_BAZA_DYSTRYBUCJI_tree_UPDATE` BEFORE UPDATE ON `IN7_MK_BAZA_DYSTRYBUCJI`
|
|
|
+ FOR EACH ROW BEGIN
|
|
|
+ -- IF NEW.P_ID<>OLD.P_ID THEN
|
|
|
+ -- SET NEW.path = IN7_MK_BAZA_DYSTRYBUCJI_hierarchy_sys_connect_by_path('-', NEW.P_ID);
|
|
|
+ -- update IN7_DZIENNIK_KORESP ik set ik.path=IN7_MK_BAZA_DYSTRYBUCJI_hierarchy_sys_connect_by_path('-', NEW.ID) where path like concat('%',NEW.ID,'%');
|
|
|
+ -- -- update PROBLEMS ik set ik.ID_PROJET_path=IN7_MK_BAZA_DYSTRYBUCJI_hierarchy_sys_connect_by_path('-', NEW.ID) where ID_PROJET_path like concat('%',NEW.ID,'%');
|
|
|
+ -- END IF;
|
|
|
+ IF NEW.`P_ID`!=OLD.`P_ID` THEN
|
|
|
+ -- send error if loop
|
|
|
+ -- OLD.path like concat('%-', NEW.P_ID, '-%')
|
|
|
+ IF OLD.ID = NEW.P_ID THEN
|
|
|
+ UPDATE `ERROR: Loop detected ID=P_ID` SET x=1;
|
|
|
+ -- #1146 - Table 'biall.ERROR: Loop detected ID=P_ID' doesn't exist
|
|
|
+ END IF;
|
|
|
+ IF NEW.P_ID > 0 THEN
|
|
|
+ -- check if project exists
|
|
|
+ IF (select count(1) from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`ID`=NEW.P_ID) = 0 THEN
|
|
|
+ UPDATE `ERROR: Parent item not exists` SET x=1;
|
|
|
+ -- #1146 - Table 'biall.ERROR: Parent item not exists' doesn't exist
|
|
|
+ END IF;
|
|
|
+ -- check loop error
|
|
|
+ -- state: 1276.path='0-868-1218-1276', 1218.path='0-868-1218'
|
|
|
+ -- update P_ID=1276 where ID=1218 - should throw error
|
|
|
+ IF (select IF(
|
|
|
+ p.`path` like concat('%-',OLD.ID,'-%')
|
|
|
+ or p.`path` like concat(OLD.ID,'-%')
|
|
|
+ , 1
|
|
|
+ , 0) from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`ID`=NEW.P_ID) > 0 THEN
|
|
|
+ UPDATE `ERROR: Loop detected in path` SET x=1;
|
|
|
+ -- #1146 - Table 'biall.ERROR: Loop detected in path' doesn't exist
|
|
|
+ END IF;
|
|
|
+ END IF;
|
|
|
+
|
|
|
+ SET NEW.`path` = (select CONCAT(
|
|
|
+ (select IF (NEW.`P_ID`>0,
|
|
|
+ coalesce(
|
|
|
+ (select p.`path` from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`ID`=NEW.`P_ID` limit 1)
|
|
|
+ , '?')
|
|
|
+ , NEW.`P_ID`
|
|
|
+ ))
|
|
|
+ , '-'
|
|
|
+ , NEW.ID
|
|
|
+ ));
|
|
|
+
|
|
|
+ -- DONT: throw warning to update all pathes in `IN7_MK_BAZA_DYSTRYBUCJI` with path under current?
|
|
|
+ -- NOTE: throw error like that prevent update fields
|
|
|
+ -- IF (select count(1) from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`P_ID`=NEW.ID) > 0 THEN
|
|
|
+ -- UPDATE `WARNING: Update all paths` SET x=1;
|
|
|
+ -- END IF;
|
|
|
+
|
|
|
+ -- DONT: update `IN7_DZIENNIK_KORESP`.`path` - rows under NEW.ID has wrong path
|
|
|
+ -- update `IN7_DZIENNIK_KORESP` k
|
|
|
+ -- set k.`path`=(select p.`path` from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`ID`=k.`ID_PROJECT`)
|
|
|
+ -- where k.`path` like concat(OLD.`path`, '-%');
|
|
|
+ -- TODO: update `PROBLEMS`.`ID_PROJECT_path` if table exists
|
|
|
+ -- update `PROBLEMS` k
|
|
|
+ -- set k.`ID_PROJECT_path`=(select p.`path` from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`ID`=k.`ID_PROJECT`)
|
|
|
+ -- where (k.`ID_PROJECT_path` like concat(OLD.`path`, '-%')
|
|
|
+ -- or k.`ID_PROJECT_path`=OLD.`path`
|
|
|
+ -- );
|
|
|
+ END IF;
|
|
|
+ END
|
|
|
+ ";
|
|
|
+ $sqlList['RemoveTrigger_AfterUpdateProject'] = "DROP TRIGGER IF EXISTS `_IN7_MK_BAZA_DYSTRYBUCJI_tree_AFTER_UPDATE`";
|
|
|
+ // throws errors:
|
|
|
+ // #1146 - Table '{DATABASE_NAME}.WARNING: Update all paths' doesn't exist
|
|
|
+ $sqlList['CreateTrigger_AfterUpdateProject'] = "
|
|
|
+ CREATE TRIGGER `_IN7_MK_BAZA_DYSTRYBUCJI_tree_AFTER_UPDATE` AFTER UPDATE ON `IN7_MK_BAZA_DYSTRYBUCJI`
|
|
|
+ FOR EACH ROW BEGIN
|
|
|
+ IF NEW.`P_ID`!=OLD.`P_ID` THEN
|
|
|
+ -- throw warning to update all pathes in `IN7_MK_BAZA_DYSTRYBUCJI` with path under current?
|
|
|
+ IF (select count(1) from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`P_ID`=NEW.ID) > 0 THEN
|
|
|
+ UPDATE `WARNING: Update all paths` SET x=1;
|
|
|
+ END IF;
|
|
|
+ END IF;
|
|
|
+ END
|
|
|
+ ";
|
|
|
+ $sqlList['RemoveEvent_everyDay'] = "DROP EVENT IF EXISTS `_IN7_MK_BAZA_DYSTRYBUCJI__IN7_DZIENNIK_KORESP_tree_event`";
|
|
|
+ $sqlList['CreateEvent_everyDay'] = "
|
|
|
+ CREATE EVENT `_IN7_MK_BAZA_DYSTRYBUCJI__IN7_DZIENNIK_KORESP_tree_event` ON SCHEDULE EVERY 1 DAY STARTS '2015-05-15 05:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
|
|
|
+ call `update_project_path_idx_rec`();
|
|
|
+ END
|
|
|
+ ";
|
|
|
$db = DB::getDB();
|
|
|
if ($db->has_errors()) {
|
|
|
throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
|