You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

queuedtask.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Jakob Sack
  6. * @copyright 2012 Jakob Sack owncloud@jakobsack.de
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * This class manages our queued tasks.
  24. */
  25. class OC_BackgroundJob_QueuedTask{
  26. /**
  27. * @brief Gets one queued task
  28. * @param $id ID of the task
  29. * @return associative array
  30. */
  31. public static function find( $id ) {
  32. $stmt = OC_DB::prepare( 'SELECT * FROM `*PREFIX*queuedtasks` WHERE `id` = ?' );
  33. $result = $stmt->execute(array($id));
  34. return $result->fetchRow();
  35. }
  36. /**
  37. * @brief Gets all queued tasks
  38. * @return array with associative arrays
  39. */
  40. public static function all() {
  41. // Array for objects
  42. $return = array();
  43. // Get Data
  44. $stmt = OC_DB::prepare( 'SELECT * FROM `*PREFIX*queuedtasks`' );
  45. $result = $stmt->execute(array());
  46. while( $row = $result->fetchRow()) {
  47. $return[] = $row;
  48. }
  49. return $return;
  50. }
  51. /**
  52. * @brief Gets all queued tasks of a specific app
  53. * @param $app app name
  54. * @return array with associative arrays
  55. */
  56. public static function whereAppIs( $app ) {
  57. // Array for objects
  58. $return = array();
  59. // Get Data
  60. $stmt = OC_DB::prepare( 'SELECT * FROM `*PREFIX*queuedtasks` WHERE `app` = ?' );
  61. $result = $stmt->execute(array($app));
  62. while( $row = $result->fetchRow()) {
  63. $return[] = $row;
  64. }
  65. // Und weg damit
  66. return $return;
  67. }
  68. /**
  69. * @brief queues a task
  70. * @param $app app name
  71. * @param $klass class name
  72. * @param $method method name
  73. * @param $parameters all useful data as text
  74. * @return id of task
  75. */
  76. public static function add( $app, $klass, $method, $parameters ) {
  77. $stmt = OC_DB::prepare( 'INSERT INTO `*PREFIX*queuedtasks` (`app`, `klass`, `method`, `parameters`)'
  78. .' VALUES(?,?,?,?)' );
  79. $result = $stmt->execute(array($app, $klass, $method, $parameters ));
  80. return OC_DB::insertid();
  81. }
  82. /**
  83. * @brief deletes a queued task
  84. * @param $id id of task
  85. * @return true/false
  86. *
  87. * Deletes a report
  88. */
  89. public static function delete( $id ) {
  90. $stmt = OC_DB::prepare( 'DELETE FROM `*PREFIX*queuedtasks` WHERE `id` = ?' );
  91. $result = $stmt->execute(array($id));
  92. return true;
  93. }
  94. }