Created
April 18, 2012 23:47
-
-
Save anandankm/2417413 to your computer and use it in GitHub Desktop.
Processing uploaded file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 public static function processUploadedFile($data) | |
67 { | |
68 $pw = new Product_Worker(); | |
69 $id = $data['ingestionId']; | |
70 error_log("ingestionId: $id"); | |
71 $pw->ia = DB_Factory::getInstance("Ingestion"); | |
72 | |
73 if (!$pw->isDataReady($id)) { | |
74 return false; | |
75 } | |
76 | |
77 $edata = new DB_EData(); | |
78 //$batch = $edata->getBatch($id); | |
79 //$pw->init($batch, $edata->getDeliveredProduct($id), "Post-upload"); | |
80 $batch = $edata->getFromFile($id, DB_EData::BATCH); | |
81 error_log("Got batch object"); | |
82 $pw->init($batch, $edata->getFromFile($id, DB_EData::DELIVERED_PRODUCT), "Post-upload"); | |
83 error_log("Got dp object"); | |
84 //$deliveredFile = $edata->getDeliveredFile($id); | |
85 $deliveredFile = $edata->getFromFile($id, DB_EData::DELIVERED_FILE); | |
86 error_log("Got product object"); | |
87 //$pw->product = $edata->getProduct($id); | |
88 $pw->product = $edata->getFromFile($id, DB_EData::PRODUCT); | |
89 | |
90 $pw->product->provider = $pw->batch->provider; | |
91 | |
92 if (!$pw->classifyProduct()) { | |
93 return false; | |
94 } | |
95 | |
96 $metadataID = $deliveredFile->track->metadataID; | |
97 try { | |
98 if (!($pw->ma->isMetadataInDB($metadataID))) { | |
99 self::$log->log("MetadataID: $metadataID does not exist. Inserting FilesSongs anyway.", 3); | |
100 } | |
101 } catch (Exception $e) { | |
102 self::$log->log("Failed to check if metadata for MetadataID: $metadataID exists. Exception:{$e->getMessage()}", 3); | |
103 } | |
104 | |
105 $returnData = array("metadataID" => $metadataID, "deliveredFileID" => $data['ingestionId'], "FileID" => $data['file']['fileId'], "albumID" => $data['song']['albumId'], "songID" => $data['song']['songId']); | |
106 | |
107 self::$log->log("Inserting FilesSongs after upload. Returndata: " . json_encode($returnData), 6); | |
108 try { | |
109 $filesSongsIDs = $pw->ma->insertFilesSongs($metadataID, $data); | |
110 } catch (Exception $e) { // unknown-error | |
111 self::$log->log($e->getMessage() . "\nDeliveredFile: $deliveredFile\nUploadResponse: ".print_r($data).";\nException: {$e->getMessage()}", 3); | |
112 return; | |
113 } | |
114 self::$log->log("Setting deliveredFile actions."); | |
115 | |
116 $deliveredFile->errorCodeID = DeliveredFile::CODE_NO_ERROR; | |
117 $pw->ia->setDeliveredFileErrorCode($deliveredFile); | |
118 $pw->ia->recordDeliveredFileAction($deliveredFile, DeliveredFile::DELIVERED_FILE_PROCESSING_COMPLETED); | |
119 $pw->ia->setDeliveredFileDBEntryToProcessed($deliveredFile); | |
120 if ($pw->ia->isAllAudioProcessed($pw->dp->deliveredProductID)) { | |
121 self::$log->log("All audio processed.", 7); | |
122 try { | |
123 if (!$pw->completeProcessing()) { | |
124 return false; | |
125 } | |
126 } catch (Exception $e) { | |
127 self::$log->log("Failed to complete processing for the product. Exception:\n{$e->getMessage()}", 3); | |
128 return false; | |
129 } | |
130 } | |
131 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment