示例#1
0
文件: Subtask.php 项目: denvolj/caked
 /**
  * This function adds new subtask.
  * 
  * @param type $taskID
  * @param type $files
  * 
  * returns int | array (when multiple files found by pattern | null (when no files found by pattern)
  */
 public static function addSubtask($taskID, $files)
 {
     if (is_array($files)) {
         $subtasks = [];
         foreach ($files as $file) {
             array_push($subtasks, self::addSubtask($taskID, $file));
         }
         return $subtasks;
     } else {
         if ($files !== NULL) {
             $ent_subtask = self::getTable()->newEntity();
             $ent_subtask->task_id = $taskID;
             $ent_subtask->file = $files;
             $ent_subtask->status = SubtaskStatus::WAIT;
             $subtask = new Subtask($ent_subtask);
             $subtask->save();
             return $subtask;
         }
     }
     return Null;
 }
示例#2
0
文件: Task.php 项目: denvolj/caked
 public function addfile($file_pattern)
 {
     $subtasks = [];
     $subtasks_checked = [];
     if (is_array($file_pattern)) {
         foreach ($file_pattern as $pattern) {
             $files = glob(realpath($this->task->directory . $pattern));
             $subtasks = array_merge($subtasks, $files);
         }
     } else {
         $subtasks = glob($this->task->directory . $file_pattern);
     }
     foreach ($subtasks as $subtask) {
         if (strpos($subtask, $this->task->directory) == 0 && !is_dir($subtask)) {
             array_push($subtasks_checked, substr($subtask, strlen($this->task->directory)));
         }
     }
     return Subtask::addSubtask($this->task->task_id, $subtasks_checked);
 }