Example #1
0
 /**
  * Delete a directory in database, but not in filesystem
  * @param string $tablename
  * @return boolean Returns TRUE on success or FALSE on failure.
  */
 public function deleteOnlyDb($tablename = '')
 {
     if ($this->getId() <= 0) {
         throw sf_exception('error', 'directory_is_not_loaded');
         return FALSE;
     }
     // check perm
     if ($this->hasPerm('delete') == FALSE) {
         throw sf_exception('error', 'permission_denied');
         return FALSE;
     }
     //first delete sub files and directories
     try {
         // delete files of directory
         $filecol = sf_api('MODEL', 'FileSqlCollection');
         $filecol->setIdclient($this->getField('idclient'));
         $filecol->setIdlang($this->getField('idlang'));
         $filecol->setFreefilter('area', $this->getField('area'));
         $filecol->setFreefilter('iddirectory', $this->getId());
         $filecol->generate();
         if ($filecol->getCount() > 0) {
             $iter = $filecol->getItemsAsIterator();
             while ($iter->valid()) {
                 $file = $iter->current();
                 //echo "delete file ".$file->getField('filename')."<br />";
                 $file->delete();
                 $iter->next();
             }
         }
         unset($filecol);
         // delete subdirectories
         $dircol = sf_api('MODEL', 'DirectorySqlCollection');
         $dircol->setIdclient($this->getField('idclient'));
         $dircol->setIdlang($this->getField('idlang'));
         $dircol->setFreefilter('area', $this->getField('area'));
         $dircol->setFreefilter('parentid', $this->getId());
         $dircol->generate();
         if ($dircol->getCount() > 0) {
             $iter = $dircol->getItemsAsIterator();
             while ($iter->valid()) {
                 $directory = $iter->current();
                 //echo "delete directory ".$directory->getField('dirname')."<br />";
                 $directory->delete();
                 $iter->next();
             }
         }
         unset($dircol);
     } catch (Exception $e) {
         // TODO collect the recursive exeptions and create a new one in the top item
         //echo $e->getMessage()."<br />";
     }
     // delete sql item
     if (parent::delete($tablename) == FALSE) {
         throw sf_exception('error', 'delete_directory_from_db_failed', array('dirname' => $fields['dirname']));
         return FALSE;
     }
     // delete rights
     if ($this->deleteAllPerms() == FALSE) {
         throw sf_exception('warning', 'delete_rights_failed', array('dirname' => $this->getField('dirname')));
         return FALSE;
     }
     return TRUE;
 }
Example #2
0
 /**
  * Add the user rights/permission for the item if perms exists.
  * @param Array $fields
  * @return Boolean|null Returns TRUE on success. Otherwise returns FALSE. And returns 'null' if no rights added.
  */
 protected function _addUserRights($fields)
 {
     // set userright after upload
     // 1. if userrights are existing ... no changes
     // 2. no userrights are existing ... xcopy directory-rights to the file, reset the directory bits
     if ($this->permsExists() == FALSE) {
         // Note: If file is in root directory (iddirectory == 0) then use area rights (e.g. area_fm, area_css, ...). Otherwise use object perm for upload.
         $permname = (int) $fields['iddirectory'] == 0 ? 'area_' . $fields['area'] : $this->objperm['upload']['type'];
         // copy userrights from directory
         $bool = $this->cfg->perm()->xcopy_perm($fields['iddirectory'], $permname, $this->getId(), $this->objperm['default']['type'], 0x1b50000, 0, 0, TRUE);
         if ($bool == FALSE) {
             throw sf_exception('warning', 'add_rights_failed', array('path' => $this->getPath($fields['area'], '', $fields['filename'])));
             return FALSE;
         }
         return TRUE;
     }
     return null;
 }