Beispiel #1
0
 protected function addToken()
 {
     do {
         $token = $this->generateToken();
         $sql = $this->pdo->prepare('INSERT INTO `upload_token` (`token`) VALUES ( :token )');
         $sql->execute(array(':token' => $token));
     } while (!$this->pdo->lastInsertId());
     $token = new UploadToken($this->pdo->lastInsertId(), $token);
     $this->tokens[$token->getToken()] = array('id' => $token->getId());
     return $token;
 }
Beispiel #2
0
 /**
  * Move the uploaded file
  * @param unknown_type $fileData
  */
 protected function handleMoveFile($fileData)
 {
     KalturaLog::info("Moving the uploaded file");
     // get the upload path
     $extension = strtolower(pathinfo($fileData['name'], PATHINFO_EXTENSION));
     $uploadFilePath = $this->getUploadPath($this->_uploadToken->getId(), $extension);
     $this->_uploadToken->setUploadTempPath($uploadFilePath);
     myContentStorage::fullMkdir($uploadFilePath);
     $moveFileSuccess = move_uploaded_file($fileData['tmp_name'], $uploadFilePath);
     if (!$moveFileSuccess) {
         $msg = "Failed to move uploaded file for token id [{$this->_uploadToken->getId()}]";
         KalturaLog::log($msg . ' ' . print_r($fileData, true));
         throw new kUploadTokenException($msg, kUploadTokenException::UPLOAD_TOKEN_FAILED_TO_MOVE_UPLOADED_FILE);
     } else {
         KalturaLog::info("The file was moved successfully");
     }
     chmod($uploadFilePath, 0777);
 }
Beispiel #3
0
 /**
  * Move the uploaded file
  * @param unknown_type $fileData
  */
 protected function handleMoveFile($fileData)
 {
     // get the upload path
     $extension = strtolower(pathinfo($fileData['name'], PATHINFO_EXTENSION));
     // in firefox html5 upload the extension is missing (file name is "blob") so try fetching the extesion from
     // the original file name that was passed to the uploadToken
     if ($extension === "" || $extension == "tmp" && $this->_uploadToken->getFileName()) {
         $extension = strtolower(pathinfo($this->_uploadToken->getFileName(), PATHINFO_EXTENSION));
     }
     $uploadFilePath = $this->getUploadPath($this->_uploadToken->getId(), $extension);
     $this->_uploadToken->setUploadTempPath($uploadFilePath);
     kFile::fullMkdir($uploadFilePath, 0700);
     $moveFileSuccess = kFile::moveFile($fileData['tmp_name'], $uploadFilePath);
     if (!$moveFileSuccess) {
         $msg = "Failed to move uploaded file for token id [{$this->_uploadToken->getId()}]";
         KalturaLog::log($msg . ' ' . print_r($fileData, true));
         throw new kUploadTokenException($msg, kUploadTokenException::UPLOAD_TOKEN_FAILED_TO_MOVE_UPLOADED_FILE);
     }
     chmod($uploadFilePath, 0600);
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      UploadToken $value A UploadToken object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(UploadToken $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) {
             self::$instances[$key] = $obj;
             kMemoryManager::registerPeer('UploadTokenPeer');
         }
     }
 }
Beispiel #5
0
 /**
  * @param UploadToken $uploadToken
  */
 public static function handleUploadFinished(UploadToken $uploadToken)
 {
     if (!is_subclass_of($uploadToken->getObjectType(), assetPeer::OM_CLASS) && $uploadToken->getObjectType() != FileAssetPeer::OM_CLASS && $uploadToken->getObjectType() != entryPeer::OM_CLASS) {
         KalturaLog::info("Class [" . $uploadToken->getObjectType() . "] not supported");
         return;
     }
     $fullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadToken->getId());
     if (!file_exists($fullPath)) {
         KalturaLog::info("File path [{$fullPath}] not found");
         $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadToken->getId(), kDataCenterMgr::getCurrentDcId());
         if (!$remoteDCHost) {
             KalturaLog::err("File path [{$fullPath}] could not be redirected");
             return;
         }
         kFileUtils::dumpApiRequest($remoteDCHost);
     }
     if ($uploadToken->getObjectType() == FileAssetPeer::OM_CLASS) {
         $dbFileAsset = FileAssetPeer::retrieveByPK($uploadToken->getObjectId());
         if (!$dbFileAsset) {
             KalturaLog::err("File asset id [" . $uploadToken->getObjectId() . "] not found");
             return;
         }
         if (!$dbFileAsset->getFileExt()) {
             $dbFileAsset->setFileExt(pathinfo($fullPath, PATHINFO_EXTENSION));
         }
         $dbFileAsset->incrementVersion();
         $dbFileAsset->save();
         $syncKey = $dbFileAsset->getSyncKey(FileAsset::FILE_SYNC_ASSET);
         try {
             kFileSyncUtils::moveFromFile($fullPath, $syncKey, true);
         } catch (Exception $e) {
             $dbFileAsset->setStatus(FileAssetStatus::ERROR);
             $dbFileAsset->save();
             throw $e;
         }
         if ($dbFileAsset->getStatus() == FileAssetStatus::UPLOADING) {
             $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
             $dbFileAsset->setSize(kFile::fileSize($finalPath));
             $dbFileAsset->setStatus(FileAssetStatus::READY);
             $dbFileAsset->save();
         }
         $uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_CLOSED);
         $uploadToken->save();
         KalturaLog::info("File asset [" . $dbFileAsset->getId() . "] handled");
         return;
     }
     if (is_subclass_of($uploadToken->getObjectType(), assetPeer::OM_CLASS)) {
         $dbAsset = assetPeer::retrieveById($uploadToken->getObjectId());
         if (!$dbAsset) {
             KalturaLog::err("Asset id [" . $uploadToken->getObjectId() . "] not found");
             return;
         }
         $ext = pathinfo($fullPath, PATHINFO_EXTENSION);
         $dbAsset->setFileExt($ext);
         $dbAsset->incrementVersion();
         $dbAsset->save();
         $syncKey = $dbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         try {
             kFileSyncUtils::moveFromFile($fullPath, $syncKey, true);
         } catch (Exception $e) {
             if ($dbAsset instanceof flavorAsset) {
                 kBatchManager::updateEntry($dbAsset->getEntryId(), entryStatus::ERROR_IMPORTING);
             }
             $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $dbAsset->save();
             throw $e;
         }
         if ($dbAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_IMPORTING) {
             $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
             $dbAsset->setSize(kFile::fileSize($finalPath));
             if ($dbAsset instanceof flavorAsset) {
                 if ($dbAsset->getIsOriginal()) {
                     $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_QUEUED);
                 } else {
                     $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING);
                 }
             } else {
                 $dbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY);
             }
             if ($dbAsset instanceof thumbAsset) {
                 list($width, $height, $type, $attr) = getimagesize($finalPath);
                 $dbAsset->setWidth($width);
                 $dbAsset->setHeight($height);
             }
             $dbAsset->save();
             kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset));
         }
         $uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_CLOSED);
         $uploadToken->save();
     }
     if ($uploadToken->getObjectType() == entryPeer::OM_CLASS) {
         $dbEntry = entryPeer::retrieveByPK($uploadToken->getObjectId());
         if (!$dbEntry) {
             KalturaLog::err("Entry id [" . $uploadToken->getObjectId() . "] not found");
             return;
         }
         //Keep original extention
         $ext = pathinfo($fullPath, PATHINFO_EXTENSION);
         // increments version
         $dbEntry->setData('100000.' . $ext);
         $dbEntry->save();
         $syncKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         try {
             kFileSyncUtils::moveFromFile($fullPath, $syncKey, true);
         } catch (Exception $e) {
             if ($dbAsset instanceof flavorAsset) {
                 kBatchManager::updateEntry($dbEntry->getId(), entryStatus::ERROR_IMPORTING);
             }
             throw $e;
         }
         $dbEntry->setStatus(entryStatus::READY);
         $dbEntry->save();
         $uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_CLOSED);
         $uploadToken->save();
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      UploadToken $value A UploadToken object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(UploadToken $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }