/** * @return string */ protected function _buildFullPath() { $fullPath = parent::_buildFullPath(); return file_exists($fullPath) ? $fullPath : "{$fullPath}.js"; }
/** * @param FileAsset $dbFileAsset * @param FileSyncKey $srcSyncKey */ protected function attachFileSync(FileAsset $dbFileAsset, FileSyncKey $srcSyncKey) { $dbFileAsset->incrementVersion(); $dbFileAsset->save(); $newSyncKey = $dbFileAsset->getSyncKey(FileAsset::FILE_SYNC_ASSET); kFileSyncUtils::createSyncFileLinkForKey($newSyncKey, $srcSyncKey); $fileSync = kFileSyncUtils::getLocalFileSyncForKey($newSyncKey, false); $fileSync = kFileSyncUtils::resolve($fileSync); $dbFileAsset->setStatus(FileAssetStatus::READY); $dbFileAsset->setSize($fileSync->getFileSize()); $dbFileAsset->save(); }
/** * AJAX behavior to process uploaded files intended as digital downloads * * Handles processing a file upload from a temporary file to a * the correct storage container (DB, file system, etc) * * @author Jonathan Davis * @return string JSON encoded result with DB id, filename, type & size **/ public static function downloads() { $error = false; if (isset($_FILES['Filedata']['error'])) { $error = $_FILES['Filedata']['error']; } if ($error) { die(json_encode(array('error' => Lookup::errors('uploads', $error)))); } if (!@is_uploaded_file($_FILES['Filedata']['tmp_name'])) { die(json_encode(array('error' => Shopp::__('The file could not be saved because the upload was not found on the server.')))); } if (0 == $_FILES['Filedata']['size']) { die(json_encode(array('error' => Shopp::__('The file could not be saved because the uploaded file is empty.')))); } FileAsset::mimetypes(); // Save the uploaded file $File = new ProductDownload(); $File->parent = 0; $File->context = "price"; $File->type = "download"; $File->name = $_FILES['Filedata']['name']; $File->filename = $File->name; list($extension, $mimetype, $properfile) = wp_check_filetype_and_ext($_FILES['Filedata']['tmp_name'], $File->name); if (empty($mimetype)) { $mimetype = 'application/octet-stream'; } $File->mime = $mimetype; if (!empty($properfile)) { $File->name = $File->filename = $properfile; } $File->size = filesize($_FILES['Filedata']['tmp_name']); $File->store($_FILES['Filedata']['tmp_name'], 'upload'); $Error = ShoppErrors()->code('storage_engine_save'); if (!empty($Error)) { die(json_encode(array('error' => $Error->message(true)))); } $File->save(); do_action('add_product_download', $File, $_FILES['Filedata']); echo json_encode(array('id' => $File->id, 'name' => stripslashes($File->name), 'type' => $File->mime, 'size' => $File->size)); }
/** * 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 FileAsset $value A FileAsset object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(FileAsset $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('FileAssetPeer'); } } }