public static function execute($eventName, $modelId = 0) { $model = new RollupEvent(); $model->name = $eventName; $model->model_id = $modelId; $model->save(); }
public function testProcessVerifyConvertToStreamsForMonths() { $this->resetEvents(); $path = $this->copyFileToTemp($this->fileName()); $s = $this->service(); $companyId = rand(1000, 1000000); $fileDetails = ["year" => 2015, "month" => 7]; $rpf = $s->process($path, $companyId, $fileDetails); $this->assertTrue($rpf->status == RoyaltyPaymentFile::STATUS_PAYMENTS_PROCESSED); $rpf = $s->processRoyaltyStreams($rpf); $this->assertTrue($rpf->status == RoyaltyPaymentFile::STATUS_PROCESSED); $streams = RoyaltyStream::all(); $this->assertTrue(count($streams) == 4); $this->assertTrue($streams[0]->royalty_country_iso == "US"); $this->assertTrue($streams[0]->royalty_currency == "USD"); $this->assertTrue($streams[0]->song_number == "60106"); $this->assertTrue($streams[0]->song_title == "10 On Top - CUES"); $this->assertTrue($streams[0]->royalty_amount == 2.71); $this->assertTrue($streams[0]->party_name == "Coon"); $this->assertTrue($streams[0]->performance_source == "ASCAP"); $this->assertTrue($streams[0]->serial_or_film == "Program Name: ONE DIRECTION ROBIN THICKE AND THE VAMPI"); $this->assertTrue($streams[0]->region == "US"); $this->assertTrue($streams[0]->number_of_plays == 0); $this->assertTrue($streams[0]->statement_period_from == "2014-01-00 00:00:00"); $this->assertTrue($streams[0]->statement_period_to == "2014-03-00 00:00:00"); $this->assertTrue($streams[0]->episode_name == ""); $this->assertTrue($streams[0]->period_year == $fileDetails["year"]); $this->assertTrue($streams[0]->period_month == $fileDetails["month"]); $this->assertTrue($streams[0]->period_quarter == 3); $this->assertTrue($streams[0]->participant_percent == 100); $this->assertTrue($streams[0]->performance_year == 2014); $this->assertTrue($streams[0]->performance_month == 1); $this->assertTrue($streams[0]->performance_quarter == 1); $this->assertTrue($streams[0]->royalty_type == "Performance"); $this->assertTrue($streams[0]->account_name == "Pop Virus (PACIFICA)"); $this->assertTrue($streams[0]->company_name == "Pacifica Music Library"); $this->assertTrue($streams[0]->company_code == "PAC1"); $this->assertTrue($streams[0]->payee_name == "Pop Virus (PACIFICA)"); $this->assertTrue($streams[0]->payee_code == "1379"); $rollupEvents = RollupEvent::all(); $this->assertTrue(count($rollupEvents) > 0); $this->resetEvents(); }
public function runRollups() { RollupEvent::EXECUTE_OVERALL_ROLLUPS(); }
protected function processDirectory($dir) { try { $path = $dir['path']; $dirName = substr($path, strrpos($path, '/') + 1); if ($this->processingEtlExists($dirName)) { $this->log($this->processingEtlKey($dirName) . " key exists, directory already processing"); return; } $this->lockProcessingEtl($dirName); $this->log("locked folder with " . $this->processingEtlKey($dirName)); if (!$this->doneExists($dirName)) { $this->log($this->doneEtlKey($dirName) . " not found directory not processable yet, removed key " . $this->processingEtlKey($dirName)); // $this->dropbox->delete($directory . "/.processing_etl"); $this->deleteProcessingEtl($dirName); return; } $this->log("Processing directory {$path}"); $dropboxMetadata = $this->dropbox->getMetadataWithChildren($path); $fileList = $dropboxMetadata['contents']; $this->log('Read data.json'); $dataFile = $this->getDataFile($path); $dataJson = $this->dropboxReadFile($dataFile); $data = json_decode($dataJson, true); $this->log('check authorization'); if (isset($data['payeeId'])) { $token = $data['payeeId']; $authorized = AuthorizationToken::findByToken($token, "User"); } else { $token = isset($data['companyId']) ? $data['companyId'] : $data['publisherId']; $authorized = AuthorizationToken::findByToken($token, "Company"); } if (empty($authorized)) { $this->log("authorization token failed"); $this->deleteProcessingEtl($dirName); return; } if (isset($data['payeeId'])) { $payee = User::find($authorized->model_id); $companyId = $payee->company_id; $payeeCode = $payee->code; } else { $companyId = $authorized->model_id; $payeeCode = null; } $this->log("authorization succeeded"); $publisherAdmins = User::publisherAdmins($companyId); $this->log('check credits'); if (!Company::hasCredits($companyId)) { $this->log("no credits available"); $this->deleteProcessingEtl($dirName); $this->sendEmailToPublisherAdminsNoCredits($publisherAdmins, $companyId); return; } $this->log("company has credits"); if (true || !isset($data['dealId'])) { $this->log('No deal id found, creating deal'); $dealName = isset($data["dealName"]) && !empty($data["dealName"]) ? $data["dealName"] : $dirName; $deal = $this->createDeal($data, $dealName, $companyId, $payeeCode); $data['dealId'] = $deal->id; $this->log("Will upload to {$dataFile}"); $this->dropbox->uploadFileFromString($dataFile, \Dropbox\WriteMode::force(), json_encode($data)); } else { $deal = Deal::find($data['dealId']); } $this->log('Deal id is ' . $deal->id); $statementList = $data['files']; foreach ($statementList as $filename => $metadata) { $this->processFile($filename, $metadata, $fileList, $deal, $path); // break; } $deal->etl_status = 'processed'; $deal->save(); $decremented = Company::decrementCredits($companyId); $this->log("decrement credits " . $decremented); if (count($publisherAdmins)) { $this->sendEmailToPublisherAdmins($publisherAdmins, $deal); $this->log("email sent to publisher"); } else { $this->log("no publisher admins found"); } $moveTo = $this->getDropboxProcessedPath() . '/' . $dirName; $this->dropbox->move($path, $moveTo); $this->log("moved to {$moveTo}"); $this->log("start executing rollups"); RollupEvent::EXECUTE_ROLLUP_TABLES($deal->id); $this->log("end executing rollups"); $this->deleteProcessingEtl($dirName); $this->log("folder unlocked"); } catch (Dropbox\Exception $e) { $this->log('dropbox error: ' . get_class($e) . ' - ' . $e->getMessage() . " FILE " . $e->getFile() . " LINE " . $e->getLine()); $this->deleteProcessingEtl($dirName); $this->log("folder unlocked"); $this->sendErrorEmailToAdmin($dir, get_class($e) . ' - ' . $e->getMessage() . " FILE " . $e->getFile() . " LINE " . $e->getLine()); } catch (Exception $e) { $this->log('something bad happened: ' . get_class($e) . ' - ' . $e->getMessage() . " FILE " . $e->getFile() . " LINE " . $e->getLine()); $this->sendErrorEmailToAdmin($dir, get_class($e) . ' - ' . $e->getMessage() . " FILE " . $e->getFile() . " LINE " . $e->getLine()); } }