Ejemplo n.º 1
0
function doScanAssets()
{
    $scanner = new ScanAssets();
    $scanner->scanAll();
}
Ejemplo n.º 2
0
 public function scan($id)
 {
     $scanner = new ScanAssets();
     $file_id = (int) $id;
     $file = new File();
     $file->findFileById($file_id);
     $success = false;
     $icon = File::getIconFromMime($file->getMime());
     if ($scanner->scanFile($file->getId())) {
         $success = true;
     }
     if ($icon === false) {
         $icon = $file->getUrl();
     }
     if ($success) {
         // we need to reload the file because scanner might have updated fields
         // and our object is out of date
         $file->findFileById($file_id);
         // move file to S3
         try {
             File::s3Upload($file->getRealPath(), APP_ATTACHMENT_PATH . $file->getFileName(), true, $file->getTitle());
             $file->setUrl(APP_ATTACHMENT_URL . $file->getFileName());
             $file->save();
             // delete the physical file now it is in S3
             unlink($file->getRealPath());
         } catch (Exception $e) {
             $success = false;
             $error = 'There was a problem uploading your file';
             error_log(__FILE__ . ": Error uploading images to S3:\n{$e}");
         }
     }
     return $this->setOutput(array('success' => $success, 'error' => isset($error) ? $error : '', 'fileid' => $file->getId(), 'url' => $file->getUrl(), 'icon' => $icon));
 }