예제 #1
0
 private static function _checkReadWrite($directory)
 {
     $directory .= '/';
     if (!is_dir($directory)) {
         echo sprintf('<tr class="fail"><td><strong>Directory %s does not exist or is not a directory.</strong></td></tr>', $directory);
         return false;
     }
     $octalPermissions = FileUtility::getOctalPermissions($directory);
     $proceed = true;
     /* Check for read. */
     if (is_readable($directory)) {
         echo sprintf('<tr class="pass"><td>Directory %s is readable (permissions: %s).</td></tr>', $directory, $octalPermissions);
     } else {
         echo sprintf('<tr class="fail"><td><strong>Directory %s is not readable (permissions: %s).</strong></td></tr>', $directory, $octalPermissions);
         $proceed = false;
     }
     /* Check for write. */
     if (is_writeable($directory)) {
         echo sprintf('<tr class="pass"><td>Directory %s is writeable (permissions: %s).</td></tr>', $directory, $octalPermissions);
     } else {
         echo sprintf('<tr class="fail"><td><strong>Directory %s is not writeable (permissions: %s).</strong></td></tr>', $directory, $octalPermissions);
         $proceed = false;
     }
     /* Test ACTUAL writeability by creating a file, not relying on is_writable()
      * as it sometimes returns a false positive.
      */
     if (FileUtility::isDirectoryWritable($directory)) {
         echo sprintf('<tr class="pass"><td>Creating a file within %s succeeded.</td></tr>', $directory);
     } else {
         echo sprintf('<tr class="fail"><td><strong>Creating a file within %s failed. Check your permissions.</strong></td></tr>', $directory);
         $proceed = false;
     }
     /* Check for create directory ability. */
     $testPath = $directory . 'testdir';
     if (is_dir($testPath)) {
         FileUtility::recursivelyRemoveDirectory($testPath);
     }
     if (@mkdir($testPath, 0777)) {
         echo sprintf('<tr class="pass"><td>Directories can be created inside %s/.</td></tr>', $directory);
     } else {
         echo sprintf('<tr class="fail"><td><strong>Directories cannot be created inside %s/.</strong></td></tr>', $directory);
         $proceed = false;
     }
     if (is_dir($testPath)) {
         FileUtility::recursivelyRemoveDirectory($testPath);
     }
     return $proceed;
 }
예제 #2
0
 /**
  * Removes all attachments associated with a Data Item ID from the
  * filesystem.
  *
  * @param flag Data Item type.
  * @param integer Data Item ID.
  * @param string Extra SQL criteria to apply to the SELECT / DELETE query.
  * @return void
  */
 public function deleteAll($dataItemType, $dataItemID, $criteria = '')
 {
     /* Get all attachment IDs for the Data Item. */
     $sql = sprintf("SELECT\n                attachment_id AS attachmentID,\n                directory_name AS directoryName\n            FROM\n                attachment\n            WHERE\n                data_item_id = %s\n            AND\n                data_item_type = %s\n            AND\n                site_id = %s\n            %s", $this->_db->makeQueryInteger($dataItemID), $this->_db->makeQueryInteger($dataItemType), $this->_siteID, $criteria);
     $rs = $this->_db->getAllAssoc($sql);
     /* Return if we have no attachments. */
     if (empty($rs)) {
         return;
     }
     foreach ($rs as $rowNumber => $row) {
         /* Sanity check. Don't delete the whole attachments directory. */
         $directoryName = trim($row['directoryName']);
         if (empty($directoryName) || ($directoryName = '.')) {
             continue;
         }
         $directory = 'attachments/' . $directoryName;
         if (is_dir($directory)) {
             FileUtility::recursivelyRemoveDirectory($directory);
         }
     }
     /* Delete the attachments metadata. */
     $sql = sprintf("DELETE FROM\n                attachment\n            WHERE\n                data_item_id = %s\n            AND\n                data_item_type = %s\n            AND\n                site_id = %s\n            %s", $this->_db->makeQueryInteger($dataItemID), $this->_db->makeQueryInteger($dataItemType), $this->_siteID, $criteria);
     $this->_db->query($sql);
 }