public static function migrate() { $errors = ''; // install all permissions as operations $permissions = array(); foreach (self::perms2opers() as $perm => $oper) { $result = OperationTable::add(self::field($oper, array())); if ($result->isSuccess()) { $permissions[$perm] = $result->getId(); } else { $errors .= 'cannot add operation: ' . $oper . "\n" . implode("\n", $result->getErrorMessages()) . "\n\n"; } } asort($permissions); // install system tasks $tasks = array(); try { $tasks[self::addTask(self::field('sale_status_none', array('SYS' => 'Y', 'LETTER' => 'D')), array())] = array(); } catch (SystemException $e) { $errors .= $e->getMessage(); } try { $tasks[self::addTask(self::field('sale_status_all', array('SYS' => 'Y', 'LETTER' => 'X')), $permissions)] = array_values($permissions); } catch (SystemException $e) { $errors .= $e->getMessage(); } // migrate permissions to tasks $result = Application::getConnection()->query('SELECT * FROM b_sale_status2group'); while ($row = $result->fetch()) { try { $taskId = self::getTaskId($row, $permissions, $tasks); $res = StatusGroupTaskTable::add(array('STATUS_ID' => $row['STATUS_ID'], 'GROUP_ID' => $row['GROUP_ID'], 'TASK_ID' => $taskId)); if (!$res->isSuccess()) { $errors .= 'cannot add status: ' . $row['STATUS_ID'] . ', group: ' . $row['GROUP_ID'] . ', task: ' . $taskId . "\n" . implode("\n", $res->getErrorMessages()) . "\n\n"; } } catch (SystemException $e) { $errors .= $e->getMessage(); } } if ($errors) { throw new SystemException($errors, 0, __FILE__, __LINE__); } }
} if ($_POST['save']) { LocalRedirect('sale_status.php?lang=' . LANGUAGE_ID . GetFilterParams('filter_', false)); } else { LocalRedirect("sale_status_edit.php?ID=" . $statusId . "&lang=" . LANGUAGE_ID . GetFilterParams("filter_", false)); } } } else { if ($statusId) { if ($row = StatusTable::getList(array('select' => array('*'), 'filter' => array('=ID' => $statusId), 'limit' => 1))->fetch()) { $status = $row; $result = StatusLangTable::getList(array('select' => array('*'), 'filter' => array('=STATUS_ID' => $statusId))); while ($row = $result->fetch()) { $translations[$row['LID']] = $row; } $result = StatusGroupTaskTable::getList(array('select' => array('*'), 'filter' => array('=STATUS_ID' => $statusId))); while ($row = $result->fetch()) { $groupTasks[$row['GROUP_ID']] = $row; } } else { $status['ID'] = $statusId; $statusId = null; } } } // V I E W ///////////////////////////////////////////////////////////////////////////////////////////////////////////// if ($statusId) { $APPLICATION->SetTitle(Loc::getMessage('SALE_EDIT_RECORD', array('#ID#' => $statusId))); } else { $APPLICATION->SetTitle(Loc::getMessage('SALE_NEW_RECORD')); }