Beispiel #1
0
 /**
  * Convert file alias to local file
  *
  * @param stored_file $storedfile a stored_file instances
  * @return stored_file stored_file
  */
 public function import_external_file(stored_file $storedfile)
 {
     global $CFG;
     require_once $CFG->dirroot . '/repository/lib.php';
     // sync external file
     repository::sync_external_file($storedfile);
     // Remove file references
     $storedfile->delete_reference();
     return $storedfile;
 }
Beispiel #2
0
 /**
  * Synchronize file if it is a reference and needs synchronizing
  *
  * Updates contenthash and filesize
  */
 public function sync_external_file()
 {
     global $CFG;
     if (!empty($this->file_record->referencefileid)) {
         require_once $CFG->dirroot . '/repository/lib.php';
         repository::sync_external_file($this);
     }
 }
Beispiel #3
0
 /**
  * Sync external files
  *
  * @return bool true if file content changed, false if not
  */
 public function sync_external_file()
 {
     global $CFG, $DB;
     if (empty($this->file_record->referencefileid)) {
         return false;
     }
     if (empty($this->file_record->referencelastsync) or $this->file_record->referencelastsync + $this->file_record->referencelifetime < time()) {
         require_once $CFG->dirroot . '/repository/lib.php';
         if (repository::sync_external_file($this)) {
             $prevcontent = $this->file_record->contenthash;
             $sql = "SELECT f.*, r.repositoryid, r.reference\n                          FROM {files} f\n                     LEFT JOIN {files_reference} r\n                               ON f.referencefileid = r.id\n                         WHERE f.id = ?";
             $this->file_record = $DB->get_record_sql($sql, array($this->file_record->id), MUST_EXIST);
             return $prevcontent !== $this->file_record->contenthash;
         }
     }
     return false;
 }