mysqli_sub_query($G_STORAGE_CONTROLLER_DBLINK, $query); # Updating our source directory $query = "\tUPDATE\n\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\tSET\n\t\t\t\t\t`files`\t\t\t=`files`-1,\n\t\t\t\t\t`filesize`\t\t=`filesize`-" . $file_data['filesize'] . ",\n\t\t\t\t\t`children_filesize`\t=`children_filesize`-" . (int) $file_data['filesize'] . ",\n\t\t\t\t\t`modified`\t\t=NOW()\n\t\t\t\tWHERE\n\t\t\t\t\t`id`=" . (int) $G_SRC_DIR_DATA['id'] . "\n\t\t\t\tLIMIT 1"; mysqli_sub_query($G_STORAGE_CONTROLLER_DBLINK, $query); # Updating the src parent directories $parent_ids = directory_parent_ids($G_STORAGE_CONTROLLER_DBLINK, $G_SRC_DIR_DATA['parent_id']); if (count($parent_ids) > 0) { # Updating our parent directories file size $query = "\tUPDATE\n\t\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`filesize`=`filesize`-" . (int) $file_data['filesize'] . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id` IN (" . implode(',', $parent_ids) . ")\n\t\t\t\t\tLIMIT 1"; mysqli_sub_query($G_STORAGE_CONTROLLER_DBLINK, $query); } # Updating our destination directory $query = "\tUPDATE\n\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\tSET\n\t\t\t\t\t`files`\t\t\t=`files`+1,\n\t\t\t\t\t`filesize`\t\t=`filesize`+" . $file_data['filesize'] . ",\n\t\t\t\t\t`children_filesize`\t=`children_filesize`+" . $file_data['filesize'] . ",\n\t\t\t\t\t`modified`\t\t=NOW()\n\t\t\t\tWHERE\n\t\t\t\t\t`id`=" . (int) $G_DEST_DIR_DATA['id'] . "\n\t\t\t\tLIMIT 1"; mysqli_sub_query($G_STORAGE_CONTROLLER_DBLINK, $query); # Updating the src parent directories $parent_ids = directory_parent_ids($G_STORAGE_CONTROLLER_DBLINK, $G_DEST_DIR_DATA['parent_id']); if (count($parent_ids) > 0) { # Updating our parent directories file size $query = "\tUPDATE\n\t\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`filesize`=`filesize`+" . (int) $file_data['filesize'] . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id` IN (" . implode(',', $parent_ids) . ")\n\t\t\t\t\tLIMIT 1"; mysqli_sub_query($G_STORAGE_CONTROLLER_DBLINK, $query); } } # We are done! PostParser::send($content); /* --- Connection closed wit PostParser::send --- Below this point things need to be tracked and cleaned up --- */ # Closing the storage connection mysqli_shared_close($G_STORAGE_CONTROLLER_DBLINK, $G_SHARED_DBLINKS); # Closing controller if tracking is different if (NQ_CONTROLLER_HOST != NQ_TRACKING_HOST) { mysqli_shared_close($G_CONTROLLER_DBLINK, $G_SHARED_DBLINKS); }
$query = "\tSELECT\n\t\t\t\t\t`id`,\n\t\t\t\t\t`meta_mime_type`,\n\t\t\t\t\t`filesize`\n\t\t\t\tFROM\n\t\t\t\t\t" . NQ_FILE_TABLE . "\n\t\t\t\tWHERE\n\t\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t\t`environment`\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "' AND\n\t\t\t\t\t`directory_id`\t=" . (int) $directory_data['id'] . " AND\n\t\t\t\t\t`name`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $_JPOST->name) . "'\n\t\t\t\tLIMIT 1"; $file_data = mysqli_single_result_query($G_STORAGE_CONTROLLER_DBLINK, $query); if (empty($file_data)) { exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_FILE); } # Archiving our file $query = "\tINSERT INTO\n\t\t\t\t\t" . NQ_FILE_PENDING_TABLE . "\n\t\t\t\t\t(\tSELECT\n\t\t\t\t\t\t\t*,\n\t\t\t\t\t\t\t`id`,\n\t\t\t\t\t\t\tNOW()\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t" . NQ_FILE_TABLE . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`id`=" . (int) $file_data['id'] . "\n\t\t\t\t\t)"; mysqli_sub_query($G_STORAGE_CONTROLLER_DBLINK, $query); # Flagging the file as deleted in the live table $query = "\tUPDATE\n\t\t\t\t\t" . NQ_FILE_TABLE . "\n\t\t\t\tSET\n\t\t\t\t\t`environment`\t\t='trash',\n\t\t\t\t\t`name`\t\t\t=CONCAT('!trash:/',`id`),\n\t\t\t\t\t`file_id`\t\t=0,\n\t\t\t\t\t`directory_id`\t\t=0,\n\t\t\t\t\t`host_id`\t\t=0,\n\t\t\t\t\t`filepath`\t\t='',\n\t\t\t\t\t`filesize`\t\t=0,\n\t\t\t\t\t`version`\t\t=0,\n\t\t\t\t\t`replicated`\t\t=0,\n\t\t\t\t\t`created`\t\t=0,\n\t\t\t\t\t`modified`\t\t=0,\n\t\t\t\t\t`meta_mime_type`\t='',\n\t\t\t\t\t`meta_width`\t\t=0,\n\t\t\t\t\t`meta_height`\t\t=0\n\t\t\t\tWHERE\n\t\t\t\t\t`id`\t\t\t=" . (int) $file_data['id'] . "\n\t\t\t\tLIMIT 1"; mysqli_sub_query($G_STORAGE_CONTROLLER_DBLINK, $query); # Deleting our directoy from the live file system $query = "\tUPDATE\n\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\tSET\n\t\t\t\t\t`files`\t\t\t=`files`-1,\n\t\t\t\t\t`filesize`\t\t=`filesize`-" . (int) $file_data['filesize'] . ",\n\t\t\t\t\t`children_filesize`\t=`children_filesize`-" . (int) $file_data['filesize'] . ",\n\t\t\t\t\t`modified`\t\t=NOW()\n\t\t\t\tWHERE\n\t\t\t\t\t`id`\t\t\t=" . (int) $directory_data['id'] . "\n\t\t\t\tLIMIT 1"; mysqli_sub_query($G_STORAGE_CONTROLLER_DBLINK, $query); # Updating the parent directories $G_PARENT_IDS = directory_parent_ids($G_STORAGE_CONTROLLER_DBLINK, $directory_data['parent_id']); # How much space we have freed $G_FILESIZE_REMOVED = $file_data['filesize']; } # Initializing our return value $content = new stdClass(); $content->success = true; $content->env = PostParser::create_attribute($G_APP_ENVIRONMENT); # We are done! PostParser::send($content); /* --- Connection closed wit PostParser::send --- Below this point things need to be tracked and cleaned up --- */ # We have some parent directories to update if (count($G_PARENT_IDS) > 0) { # Updating our parent directories file size $query = "\tUPDATE\n\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\tSET\n\t\t\t\t\t`filesize`=`filesize`-" . (int) $G_FILESIZE_REMOVED . "\n\t\t\t\tWHERE\n\t\t\t\t\t`id` IN (" . implode(',', $G_PARENT_IDS) . ")\n\t\t\t\tLIMIT 1"; mysqli_sub_query($G_STORAGE_CONTROLLER_DBLINK, $query);
exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_FILE); } # Deleteing our trashed file $query = "\tDELETE FROM\n\t\t\t\t\t" . NQ_FILE_TABLE . "\n\t\t\t\tWHERE\n\t\t\t\t\t`id`=" . (int) $file_data['id'] . "\n\t\t\t\tLIMIT 1"; mysqli_sub_query($G_CONTROLLER_DBLINK, $query); # Unarchiving our file $query = "\tINSERT INTO\n\t\t\t\t\t" . NQ_FILE_TABLE . "\n\t\t\t\t\t(\tSELECT\n\t\t\t\t\t\t\t`id`,\n\t\t\t\t\t\t\t`app_id`,\n\t\t\t\t\t\t\t`environment`,\n\t\t\t\t\t\t\t`file_id`,\n\t\t\t\t\t\t\t`name`,\n\t\t\t\t\t\t\t`directory_id`,\n\t\t\t\t\t\t\t`host_id`,\n\t\t\t\t\t\t\t`filepath`,\n\t\t\t\t\t\t\t`filesize`,\n\t\t\t\t\t\t\t`version`,\n\t\t\t\t\t\t\t`replicated`,\n\t\t\t\t\t\t\t`created`,\n\t\t\t\t\t\t\t`modified`,\n\t\t\t\t\t\t\t`meta_mime_type`,\n\t\t\t\t\t\t\t`meta_width`,\n\t\t\t\t\t\t\t`meta_height`\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t" . NQ_FILE_PENDING_TABLE . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`id`=" . (int) $file_data['id'] . "\n\t\t\t\t\t)"; mysqli_sub_query($G_CONTROLLER_DBLINK, $query); # Removing from the live list $query = "\tDELETE FROM\n\t\t\t\t\t" . NQ_FILE_PENDING_TABLE . "\n\t\t\t\tWHERE\n\t\t\t\t\t`id`=" . (int) $file_data['id'] . "\n\t\t\t\tLIMIT 1"; mysqli_sub_query($G_CONTROLLER_DBLINK, $query); # Deleting our directoy from the live file system $query = "\tUPDATE\n\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\tSET\n\t\t\t\t\t`files`\t\t\t=`files`+1,\n\t\t\t\t\t`filesize`\t\t=`filesize`+" . (int) $file_data['filesize'] . ",\n\t\t\t\t\t`children_filesize`\t=`children_filesize`+" . (int) $file_data['filesize'] . ",\n\t\t\t\t\t`modified`\t\t=NOW()\n\t\t\t\tWHERE\n\t\t\t\t\t`id`=" . (int) $directory_data['id'] . "\n\t\t\t\tLIMIT 1"; mysqli_sub_query($G_CONTROLLER_DBLINK, $query); # Updating the parent directories $parent_ids = directory_parent_ids($G_CONTROLLER_DBLINK, $directory_data['parent_id']); if (count($parent_ids) > 0) { # Updating our directory parent directories file size $query = "\tUPDATE\n\t\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`filesize`=`filesize`+" . (int) $file_data['filesize'] . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id` IN (" . implode(',', $parent_ids) . ")\n\t\t\t\t\tLIMIT 1"; mysqli_sub_query($G_CONTROLLER_DBLINK, $query); } # Adding our data $size = $file_data['filesize']; $file_type = $file_data['meta_mime_type']; # How much space we have freed $G_FILESIZE_ADDED = $file_data['filesize']; } # Initializing our return value $content = new stdClass(); $content->success = true; $content->env = PostParser::create_attribute($G_APP_ENVIRONMENT);