filterByDbService(static::$_SERVICE_NAME) ->findOneByDbFileId($fileId); if (is_null($ref)) { $ref = new ThirdPartyTrackReferences(); } $ref->setDbService(static::$_SERVICE_NAME); $ref->setDbFileId($fileId); $ref->save(); return $ref->getDbId(); } /** * Remove a ThirdPartyTrackReferences row from the database. * This is necessary if the track was removed from the service * or the foreign id in our database is incorrect * * @param $fileId int cc_files identifier * * @throws Exception * @throws PropelException */ public function removeTrackReference($fileId) { $ref = ThirdPartyTrackReferencesQuery::create() ->filterByDbService(static::$_SERVICE_NAME) ->findOneByDbFileId($fileId); $ref->delete(); } /** * Given a CcFiles identifier for a file that's been uploaded to a third-party service, * return the third-party identifier for the remote file * * @param int $fileId the cc_files identifier * * @return string the service foreign identifier */ public function getServiceId($fileId) { $ref = ThirdPartyTrackReferencesQuery::create() ->filterByDbService(static::$_SERVICE_NAME) ->findOneByDbFileId($fileId); // There shouldn't be duplicates! return empty($ref) ? '' : $ref->getDbForeignId(); } /** * Check if a reference exists for a given CcFiles identifier * * @param int $fileId the cc_files identifier * * @return string the service foreign identifier */ public function referenceExists($fileId) { $ref = ThirdPartyTrackReferencesQuery::create() ->filterByDbService(static::$_SERVICE_NAME) ->findOneByDbFileId($fileId); // There shouldn't be duplicates! if (!empty($ref)) { $task = CeleryTasksQuery::create() ->findOneByDbTrackReference($ref->getDbId()); return $task->getDbStatus() != CELERY_FAILED_STATUS; } return false; } }