|
|
@@ -26,13 +26,13 @@ Lib::loadClass('RouteBase');
|
|
|
*/
|
|
|
class Route_Msgs extends RouteBase {
|
|
|
|
|
|
- public function handleAuth() {
|
|
|
+ function handleAuth() {
|
|
|
if (!User::logged()) {
|
|
|
throw new HttpException('Unauthorized', 401);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function defaultAction() {
|
|
|
+ function defaultAction() {
|
|
|
SE_Layout::gora();
|
|
|
?>
|
|
|
<div class="container">
|
|
|
@@ -43,17 +43,17 @@ class Route_Msgs extends RouteBase {
|
|
|
SE_Layout::dol();
|
|
|
}
|
|
|
|
|
|
- public function reinstallAction() {
|
|
|
+ function reinstallAction() {
|
|
|
$this->reinstall();
|
|
|
die('OK');
|
|
|
}
|
|
|
|
|
|
- public function reinstallFunctionsAction() {
|
|
|
+ function reinstallFunctionsAction() {
|
|
|
$this->reinstallFunctions();
|
|
|
die('OK');
|
|
|
}
|
|
|
|
|
|
- public function runAction() {
|
|
|
+ function runAction() {
|
|
|
$msgId = V::get('_msgId', 0, $_REQUEST, 'int');
|
|
|
if ($msgId > 0) {
|
|
|
$this->runByMessageId($msgId);
|
|
|
@@ -65,15 +65,7 @@ class Route_Msgs extends RouteBase {
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
- public function addTestMsgAction() {
|
|
|
- $sql = "INSERT INTO `CRM_UI_MSGS` (`ID`, `app_className`, `msg`, `msgType`, `uiTargetType`, `uiTargetName`, `userTargetType`, `userTargetName`, `actionExecutedTime`, `actionNotes`, `A_RECORD_CREATE_DATE`, `A_RECORD_CREATE_AUTHOR`, `A_RECORD_UPDATE_DATE`, `A_RECORD_UPDATE_AUTHOR`)
|
|
|
- VALUES (NULL, 'FixZasobPath', 'Update all paths', 'danger', 'default_db_table', 'CRM_LISTA_ZASOBOW', 'user', 'plabudda', NULL, '', NULL, 'plabudda', NULL, '')";
|
|
|
- $db = DB::getDB();
|
|
|
- $db->query($sql);
|
|
|
- die('OK');
|
|
|
- }
|
|
|
-
|
|
|
- public function reinstallFunctions() {
|
|
|
+ function reinstallFunctions() {
|
|
|
$sqlList = array();
|
|
|
//$sqlList['RemoveTable_CRM_UI_MSGS__EXEC_LOG'] = "DROP TABLE IF EXISTS `CRM_UI_MSGS__EXEC_LOG`";
|
|
|
$sqlList['CreateTable_CRM_UI_MSGS__EXEC_LOG'] = "
|
|
|
@@ -226,19 +218,12 @@ SQL_QUERY;
|
|
|
END IF;
|
|
|
|
|
|
SQL_QUERY;
|
|
|
- $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()));
|
|
|
- }
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function reinstall() {
|
|
|
+ function reinstall() {
|
|
|
$sqlList = array();
|
|
|
//$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `CRM_UI_MSGS`";// TODO: update struct (add cells, rm old keys) - not drop/create
|
|
|
$sqlList['InstallTable'] = "
|
|
|
@@ -274,20 +259,13 @@ SQL_QUERY;
|
|
|
, KEY `app_className` (`app_className`)
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin2
|
|
|
";
|
|
|
- $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()));
|
|
|
- }
|
|
|
+ DB::getPDO()->execSql($sql);
|
|
|
}
|
|
|
$this->reinstallFunctions();
|
|
|
}
|
|
|
|
|
|
- public function getActiveMessagesForTable($tblName) {
|
|
|
+ function getActiveMessagesForTable($tblName) {
|
|
|
if (empty($tblName)) return;
|
|
|
$sqlTableName = DB::getPDO()->quote($tblName);
|
|
|
$usrLogin = User::getLogin();
|
|
|
@@ -314,7 +292,7 @@ SQL_QUERY;
|
|
|
return $msgs;
|
|
|
}
|
|
|
|
|
|
- public function getActiveMessagesForTableRecord($tblName, $id) {
|
|
|
+ function getActiveMessagesForTableRecord($tblName, $id) {
|
|
|
if (empty($tblName)) return;
|
|
|
$usrLogin = User::getLogin();
|
|
|
$msgs = [];
|
|
|
@@ -343,7 +321,7 @@ SQL_QUERY;
|
|
|
return $msgs;
|
|
|
}
|
|
|
|
|
|
- public function parseMessage($r) {
|
|
|
+ function parseMessage($r) {
|
|
|
$msg = null;// ['type'=>'info', 'message'=>'...']
|
|
|
// $r->app_className - for automatic msgs to search for msg text
|
|
|
// $r->msg - for automatic msgs to search for msg text
|
|
|
@@ -363,11 +341,11 @@ SQL_QUERY;
|
|
|
return $msg;
|
|
|
}
|
|
|
|
|
|
- public function parseMessageFromMsgsSystem($msg) {
|
|
|
+ function parseMessageFromMsgsSystem($msg) {
|
|
|
return $msg;
|
|
|
}
|
|
|
|
|
|
- public function runByMessageId($id) {
|
|
|
+ function runByMessageId($id) {
|
|
|
$msgRow = $this->getActiveMessage($id);
|
|
|
$execNotes = '';
|
|
|
if (!empty($msgRow->app_className)) {
|
|
|
@@ -386,56 +364,43 @@ SQL_QUERY;
|
|
|
return ($msg) ? (object)$msg : null;
|
|
|
}
|
|
|
|
|
|
- public function getActiveMessage($id) {
|
|
|
+ function getActiveMessage($id) {
|
|
|
if (empty($id)) return;
|
|
|
$id = intval($id);
|
|
|
if ($id <= 0) return;
|
|
|
|
|
|
- $msg = null;
|
|
|
- $sql = "select m.*
|
|
|
- from `CRM_UI_MSGS` m
|
|
|
- where m.`ID`='{$id}'
|
|
|
- and m.`A_STATUS`='WAITING'
|
|
|
- ";
|
|
|
- $db = DB::getDB();
|
|
|
- $res = $db->query($sql);
|
|
|
- if ($r = $db->fetch($res)) {
|
|
|
- $msg = $r;
|
|
|
- }
|
|
|
- if (!$msg) {
|
|
|
- throw new HttpException("Message not found", 404);
|
|
|
- }
|
|
|
+ $msg = DB::getPDO()->fetchFirst("
|
|
|
+ select m.*
|
|
|
+ from CRM_UI_MSGS m
|
|
|
+ where m.ID = :id
|
|
|
+ and m.A_STATUS = 'WAITING'
|
|
|
+ ", [
|
|
|
+ ':id' => $id,
|
|
|
+ ]);
|
|
|
+ if (!$msg) throw new HttpException("Message not found", 404);
|
|
|
return $msg;
|
|
|
}
|
|
|
|
|
|
- public function forceFinishMessage($id, $execNotes) {
|
|
|
+ function forceFinishMessage($id, $execNotes) {
|
|
|
if (empty($id)) return;
|
|
|
$id = intval($id);
|
|
|
if ($id <= 0) return;
|
|
|
|
|
|
- $usrLogin = User::getLogin();
|
|
|
- $db = DB::getDB();
|
|
|
- $execNotes = $db->_($execNotes);
|
|
|
- $sql = "update `CRM_UI_MSGS`
|
|
|
- set `A_STATUS`='OFF_HARD'
|
|
|
- , `actionExecutedTime`=NOW()
|
|
|
- , `actionNotes`='{$execNotes}'
|
|
|
- , `A_RECORD_UPDATE_DATE`=NOW()
|
|
|
- , `A_RECORD_UPDATE_AUTHOR`='{$usrLogin}'
|
|
|
- where `ID`='{$id}'
|
|
|
- ";
|
|
|
- $db->query($sql);
|
|
|
- return;
|
|
|
+ DB::getPDO()->update('CRM_UI_MSGS', 'ID', $id, [
|
|
|
+ 'A_STATUS' => "OFF_HARD",
|
|
|
+ 'actionExecutedTime' => "NOW()",
|
|
|
+ 'actionNotes' => $execNotes,
|
|
|
+ 'A_RECORD_UPDATE_DATE' => "NOW()",
|
|
|
+ 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
- public function removeMessage($id) {
|
|
|
+ function removeMessage($id) {
|
|
|
if (empty($id)) return;
|
|
|
$id = intval($id);
|
|
|
if ($id <= 0) return;
|
|
|
|
|
|
- $sql = "update `CRM_UI_MSGS` set `A_STATUS`='DELETED' where `ID`='{$id}' ";
|
|
|
- $db = DB::getDB();
|
|
|
- $db->query($sql);
|
|
|
+ DB::getPDO()->execSql(" update `CRM_UI_MSGS` set `A_STATUS`='DELETED' where `ID` = :id ", [ ':id' => $id ]);
|
|
|
}
|
|
|
|
|
|
function removeTableRecordMsg($idMsg) {
|