public function Execute($db, $params) { $asset = null; $assetID = null; $response = array(); if (isset($params["EncodedData"]) && isset($params["ContentType"])) { log_message('debug', "xAddAsset asset"); // Build the asset structure from the parameters $asset = new Asset(); if (!isset($params["AssetID"]) || !UUID::TryParse($params["AssetID"], $asset->ID)) { $asset->ID = UUID::Random(); } if (!isset($params["CreatorID"]) || !UUID::TryParse($params["CreatorID"], $asset->CreatorID)) { $asset->CreatorID = UUID::Zero; } $asset->Data = base64_decode($params["EncodedData"]); $asset->SHA256 = hash("sha256", $asset->Data); $asset->ContentLength = strlen($asset->Data); $asset->ContentType = $params["ContentType"]; $asset->Temporary = !empty($params["Temporary"]); $asset->Public = !empty($params["Public"]); $assets = new SQLAssets($db); $created = false; if ($assets->AddAsset($asset, $created)) { $response['Success'] = TRUE; $response['AssetID'] = $asset->ID; $response['Status'] = $created ? "created" : "updated"; } else { log_message('warn', 'failed to create asset'); $response['Success'] = FALSE; $response['Message'] = 'failed to create the asset'; } } else { $response['Success'] = FALSE; $response['Message'] = 'missing required parameters'; } log_message('debug', sprintf("[AddAsset] result %s", json_encode($response))); header("Content-Type: application/json", true); echo json_encode($response); exit; }
public function Execute($db, $asset) { $assets = new SQLAssets($db); //$assets = new MongoAssets($db); $created = false; if ($assets->AddAsset($asset, $created)) { if ($created) { $status = "Created"; } else { $status = "Updated"; } log_message('debug', "AddClass Succesfully {$status} " . $asset->ID); header("Content-Type: application/json", true); echo '{ "Success": true, "AssetID": "' . $asset->ID . '", "Status": "' . $status . '" }'; exit; } else { header("Content-Type: application/json", true); echo '{ "Message": "Unable to store asset" }'; exit; } }