Example #1
0
 /**
  * Remove a directory
  *
  * @access public
  *
  * @param $pi path information
  */
 public static function rmdir($pi)
 {
     Log::in("query - rmdir");
     Query::fillCategoryId($pi);
     $category = $pi[PI_CATEGORYID];
     /* Can't delete uncategorized */
     if ($category == 0) {
         Log::out("query - rmdir - cannot delete uncategorized");
         return -FUSE_ENOENT;
     }
     /* Ok, delete the category */
     $dbConn = Pool::get();
     $prefix = Pool::getTableprefix();
     Log::output("query - rmdir - create sql - delete");
     $sql = "DELETE FROM ";
     $sql .= "`{$prefix}" . "categories`";
     $sql .= " WHERE id = '{$category}'";
     /* Check for failure */
     Log::output("query - rmdir - check for failure");
     $result = mysql_query($sql, $dbConn);
     $rows = mysql_affected_rows($dbConn);
     if ($result === false || $rows == 0) {
         $error = mysql_error($dbConn);
         Log::output($error);
         Pool::release($dbConn);
         Log::out("query - rmdir failed");
         return -FUSE_EIO;
     }
     /* OK, update all other content tables to set the old category
      * to uncategorized. Don't check this, just do it.
      */
     $sql = "UPDATE ";
     $sql .= "`{$prefix}" . "site_htmlsnippets`";
     $sql .= " SET category = '0'";
     $sql .= " WHERE category = '{$category}'";
     mysql_query($sql, $dbConn);
     $sql = "UPDATE ";
     $sql .= "`{$prefix}" . "site_modules`";
     $sql .= " SET category = '0'";
     $sql .= " WHERE category = '{$category}'";
     mysql_query($sql, $dbConn);
     $sql = "UPDATE ";
     $sql .= "`{$prefix}" . "site_plugins`";
     $sql .= " SET category = '0'";
     $sql .= " WHERE category = '{$category}'";
     mysql_query($sql, $dbConn);
     $sql = "UPDATE ";
     $sql .= "`{$prefix}" . "site_snippets`";
     $sql .= " SET category = '0'";
     $sql .= " WHERE category = '{$category}'";
     mysql_query($sql, $dbConn);
     $sql = "UPDATE ";
     $sql .= "`{$prefix}" . "site_templates`";
     $sql .= " SET category = '0'";
     $sql .= " WHERE category = '{$category}'";
     mysql_query($sql, $dbConn);
     /* Success */
     Pool::release($dbConn);
     Log::out("query - rmdir");
     return 0;
 }