Пример #1
0
 /**
  * Create a new record in the Managedfile table or return an existing one.
  * If $verifypath == TRUE, a new record will be created only if the file exists.
  *
  * @param string $path      Relative path offset from the www/ folder
  * @param boolean $verifypath
  * @return NULL|Managedfile
  */
 public static function createManagedfileRow($path, $verifypath = false)
 {
     $create = true;
     if ($verifypath) {
         $fullpath = Curry_Core::$config->curry->wwwPath . DIRECTORY_SEPARATOR . $path;
         $create = file_exists($fullpath);
     }
     $managedfile = null;
     if ($create) {
         $entityType = self::getEntityType($path);
         if ($entityType === self::ENTITY_TYPE_DIR) {
             $path .= DIRECTORY_SEPARATOR;
         }
         // check whether the record exists in the Managedfile table.
         $managedfile = ManagedfileQuery::create()->findOneByFilepath($path);
         if ($managedfile) {
             return $managedfile;
         }
         $mime = self::getMimeType($path);
         $managedfile = new Managedfile();
         $managedfile->setFilepath($path)->setType($entityType)->setFilemime($mime)->setOwner(User::getUser())->save();
     }
     return $managedfile;
 }