/** * * @param type $fileName * @param type $idServiceSet * @param array $scheduleData * @param type $packageName * @param type $isReady * @throws Logic_Exception */ public function createPackageFromFile($fileName, $idServiceSet, $packageName = null) { $pathInfo = pathinfo($fileName); if (false === is_readable($fileName)) { throw new Logic_Exception("Cannot access file {$fileName}"); } $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); $updloadDir = $config->uploads->destination; $destFileName = uniqid() . '.' . $pathInfo['extension']; if (false == is_writable($updloadDir) || false == copy($fileName, $updloadDir . DIRECTORY_SEPARATOR . $destFileName)) { throw new Logic_Exception("Cannot access directory {$updloadDir}"); } unlink($fileName); $package = new WsPackage(); $dataToSavePackage = array('ws_service_set_id' => $idServiceSet, 'name' => $packageName, 'file_name' => $destFileName); $package->getDefaultAdapter()->beginTransaction(); try { $idPackage = $package->createRow($dataToSavePackage)->save(); $this->updatePackageStatus($idPackage, WsPackageStatus::STATUS_NEW); $package->getDefaultAdapter()->commit(); } catch (Exception $exc) { $package->getDefaultAdapter()->rollBack(); unlink($updloadDir . DIRECTORY_SEPARATOR . $destFileName); throw new Logic_Exception("Cannot add package info into database.", null, $exc); } return $idPackage; }