Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CommandsBusiness.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Http\Business;
  3. use Luticate\Utils\LuBusiness;
  4. use App\Http\DataAccess\CommandsDataAccess;
  5. use App\Http\DBO\CommandsDbo;
  6. class CommandsBusiness extends LuBusiness {
  7. protected static function getDataAccess()
  8. {
  9. return new CommandsDataAccess();
  10. }
  11. protected static function checkCommand(CommandsDbo $command, $command_id = null)
  12. {
  13. $existingCommand = CommandsDataAccess::getByName($command->getName());
  14. if (!is_null($existingCommand) && $command_id != $existingCommand->getId()) {
  15. self::badInput("Command name already exists");
  16. }
  17. if (is_null($command->getName()) || strlen($command->getName()) == 0) {
  18. self::badInput("Missing command name");
  19. }
  20. HostsBusiness::getById($command->getHostId());
  21. CommandTypesBusiness::getById($command->getCommandTypeId());
  22. if (is_null($command->getDescription())) {
  23. $command->setDescription("");
  24. }
  25. if (is_null($command->getData()) || strlen($command->getData()) == 0) {
  26. $command->setData("{}");
  27. }
  28. $json = json_decode($command->getData());
  29. if (is_null($json)) {
  30. self::badInput("Command data could not be converted to json");
  31. }
  32. }
  33. public static function add(CommandsDbo $command)
  34. {
  35. self::checkCommand($command);
  36. return CommandsDataAccess::addId($command);
  37. }
  38. public static function edit(CommandsDbo $command, $command_id)
  39. {
  40. self::getById($command_id);
  41. self::checkCommand($command, $command_id);
  42. $command->setId($command_id);
  43. return CommandsDataAccess::editById($command_id, $command);
  44. }
  45. public static function exec($command_id)
  46. {
  47. self::getById($command_id);
  48. return true;
  49. }
  50. }