123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
-
- namespace App\Http\Business;
-
- use Luticate\Utils\LuBusiness;
- use App\Http\DataAccess\CommandsDataAccess;
- use App\Http\DBO\CommandsDbo;
-
- class CommandsBusiness extends LuBusiness {
- protected static function getDataAccess()
- {
- return new CommandsDataAccess();
- }
-
- protected static function checkCommand(CommandsDbo $command, $command_id = null)
- {
- $existingCommand = CommandsDataAccess::getByName($command->getName());
- if (!is_null($existingCommand) && $command_id != $existingCommand->getId()) {
- self::badInput("Command name already exists");
- }
- if (is_null($command->getName()) || strlen($command->getName()) == 0) {
- self::badInput("Missing command name");
- }
- HostsBusiness::getById($command->getHostId());
- CommandTypesBusiness::getById($command->getCommandTypeId());
- if (is_null($command->getDescription())) {
- $command->setDescription("");
- }
- if (is_null($command->getData()) || strlen($command->getData()) == 0) {
- $command->setData("{}");
- }
- $json = json_decode($command->getData());
- if (is_null($json)) {
- self::badInput("Command data could not be converted to json");
- }
- }
-
- public static function add(CommandsDbo $command)
- {
- self::checkCommand($command);
- return CommandsDataAccess::addId($command);
- }
-
- public static function edit(CommandsDbo $command, $command_id)
- {
- self::getById($command_id);
- self::checkCommand($command, $command_id);
- $command->setId($command_id);
- return CommandsDataAccess::editById($command_id, $command);
- }
-
- public static function exec($command_id)
- {
- self::getById($command_id);
- return true;
- }
- }
|