Ejemplo n.º 1
0
		IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
		FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
		AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
		LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
		OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
		THE SOFTWARE.
*/
# Including our configuration and validate app
require_once __DIR__ . '/_includes/config.php';
require_once __DIR__ . '/_includes/validate-app.php';
# Handling our global json parsing
$_JPOST = PostParser::decode();
# Fetching our domain
$query = "\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\t" . NQ_CONSTANT_TABLE . "\n\t\t\tWHERE\n\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t`environment`\tIN ('*','" . mysqli_escape_string($G_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "') AND\n\t\t\t\t`tag`\t\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $_JPOST->tag) . "'\n\t\t\tLIMIT 1";
$constant_data = mysqli_single_result_query($G_CONTROLLER_DBLINK, $query);
# Validating the app owns the constant
if (!isset($constant_data['id'])) {
    exit_fail(0, 'Invalid constant.');
}
# Adding our domain
$query = "\tUPDATE\n\t\t\t\t" . NQ_CONSTANT_TABLE . "\n\t\t\tSET\n\t\t\t\t`name`\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $_JPOST->name) . "',\n\t\t\t\t`text`\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $_JPOST->text) . "'\n\t\t\tWHERE\n\t\t\t\t`id`\t\t=" . (int) $constant_data['id'] . "\n\t\t\tLIMIT 1";
mysqli_sub_query($G_CONTROLLER_DBLINK, $query);
# The content to be returned
$content = new stdClass();
$content->success = true;
$content->query = $query;
# Sending our content
$strlen = PostParser::send($content);
# Tracking our endpoint
track_endpoint($G_CONTROLLER_DBLINK, $G_APP_DATA['id'], $G_APP_ENVIRONMENT, $_ENDPOINT, $strlen);
Ejemplo n.º 2
0
    $this_size_changed = false;
    if ((int) $partition->data['size'] != (int) $size_data['size']) {
        # Flag size changed
        $size_changed = true;
        $this_size_changed = true;
        # Storing the currently saved size
        $update_queries[] = "\tSET @size_delta = \t(\n\t\t\t\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\t\t\t" . (int) $size_data['size'] . "- CONVERT(`size`,SIGNED)\n\t\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t`id`=" . (int) $id . "\n\t\t\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t\t\t)";
        # Updating our size change
        $update_queries[] = "\tSET @table_size_delta = @table_size_delta + @size_delta";
    }
    # Updating the partitions size
    $update_queries[] = "\tUPDATE\n\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t" . ($this_size_changed ? "`size` = `size` + @size_delta," : "") . "\n\t\t\t\t\t\t`modified`\t=NOW(),\n\t\t\t\t\t\t`accessed`\t=NOW()\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`\t\t=" . (int) $id . "\n\t\t\t\t\tLIMIT 1";
}
# Updating the table
$update_queries[] = "\tUPDATE\n\t\t\t\t\t" . NQ_TABLE_SETTINGS_TABLE . "\n\t\t\t\tSET\n\t\t\t\t\t" . ($size_changed ? "`size` = `size` + @table_size_delta," : "") . "\n\t\t\t\t\t`modified`\t=NOW(),\n\t\t\t\t\t`accessed`\t=NOW()\n\t\t\t\tWHERE\n\t\t\t\t\t`id`\t\t=" . (int) $G_TABLE_DETAILS['id'] . "\n\t\t\t\tLIMIT 1";
# Adjusting our app database size
if ($size_changed) {
    $update_queries[] = "\tUPDATE\n\t\t\t\t\t\t" . NQ_APPS_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`db_size`=`db_size`+ @table_size_delta\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`=" . (int) $G_APP_DATA['id'] . "\n\t\t\t\t\tLIMIT 1";
}
# Running our update queries
mysqli_multi_sub_query($G_CONTROLLER_DBLINK, implode(';', $update_queries));
# Opening our tracking dblink
$G_TRACKING_DBLINK = mysqli_shared_connect(NQ_TRACKING_HOST, NQ_TRACKING_USERNAME, NQ_TRACKING_PASSWORD, $G_SHARED_DBLINKS);
# Closing the controller dblink
mysqli_shared_close($G_CONTROLLER_DBLINK, $G_SHARED_DBLINKS);
# Adding table analytics
$query = "\tINSERT INTO\n\t\t\t\t" . NQ_TRACKING_TABLE_IO . "\n\t\t\tSET\n\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . ",\n\t\t\t\t`table_id`\t=" . (int) $G_TABLE_DETAILS['id'] . ",\n\t\t\t\t`environment`\t='" . mysqli_escape_string($G_TRACKING_DBLINK, $G_APP_ENVIRONMENT) . "',\n\t\t\t\t`writes`\t=1,\n\t\t\t\t`write_rows`\t=" . (int) $content->affected_rows . ",\n\t\t\t\t`created`\t='" . date('Y-m-d H:00:00') . "'";
mysqli_sub_query($G_TRACKING_DBLINK, $query);
# Adding our usage - Always call this last
track_endpoint($G_SHARED_DBLINKS, $G_APP_DATA['id'], $G_APP_ENVIRONMENT, $_ENDPOINT);
Ejemplo n.º 3
0
    $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);
# We are done!
PostParser::send($content);
/* --- Connection closed wit PostParser::send --- Below this point things need to be tracked and cleaned up --- */
# Updating our app
$query = "\tUPDATE\n\t\t\t\t" . NQ_APPS_TABLE . "\n\t\t\tSET\n\t\t\t\t`storage_img_size`\t=`storage_img_size`+" . (int) $G_FILESIZE_ADDED . ",\n\t\t\t\t`storage_total_size`\t=`storage_total_size`+" . (int) $G_FILESIZE_ADDED . "\n\t\t\tWHERE\n\t\t\t\t`id`\t\t\t\t=" . (int) $G_APP_DATA['id'] . "\n\t\t\tLIMIT 1";
mysqli_sub_query($G_CONTROLLER_DBLINK, $query);
# Adding our usage
track_endpoint($G_CONTROLLER_DBLINK, $G_APP_DATA['id'], $G_APP_ENVIRONMENT, $_ENDPOINT, (int) $size, $file_type);