Exemple #1
0
 public static function add($filename, $prefix, $data = array(), $fsl = false)
 {
     $db = Loader::db();
     $dh = Loader::helper('date');
     $date = $dh->getOverridableNow();
     if (!is_object($fsl)) {
         $fsl = StorageLocation::getDefault();
     }
     $uID = 0;
     $u = new User();
     if (isset($data['uID'])) {
         $uID = $data['uID'];
     } else {
         if ($u->isRegistered()) {
             $uID = $u->getUserID();
         }
     }
     $f = new self();
     $f->uID = $uID;
     $f->storageLocation = $fsl;
     $f->fDateAdded = new Carbon($date);
     $em = \ORM::entityManager('core');
     $em->persist($f);
     $em->flush();
     $fv = Version::add($f, $filename, $prefix, $data);
     $f->versions->add($fv);
     $fve = new \Concrete\Core\File\Event\FileVersion($fv);
     Events::dispatch('on_file_add', $fve);
     $entities = $u->getUserAccessEntityObjects();
     $hasUploader = false;
     foreach ($entities as $obj) {
         if ($obj instanceof FileUploaderPermissionAccessEntity) {
             $hasUploader = true;
         }
     }
     if (!$hasUploader) {
         $u->refreshUserGroups();
     }
     return $fv;
 }