fix the mess
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
@@ -17,38 +17,51 @@
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Assets;
|
||||
|
||||
interface AssetManagerInterface
|
||||
{
|
||||
interface AssetManagerInterface {
|
||||
/**
|
||||
* Prepare an asset directory.
|
||||
* Prepare an asset directory by checking that no changes occured in
|
||||
* the source directory. If any change is detected, the whole asset directory
|
||||
* is copied in the web space.
|
||||
*
|
||||
* @param string $sourceAssetsDirectory the full path to the source asstes directory
|
||||
* @param string $webAssetsDirectoryBase the base directory of the web based asset directory
|
||||
* @param $webAssetsTemplate
|
||||
* @param string $webAssetsKey the assets key : module name or 0 for base template
|
||||
*
|
||||
* @param string $source_assets_directory the full path to the source asstes directory
|
||||
* @param string $web_assets_directory_base the base directory of the web based asset directory
|
||||
* @throws \RuntimeException if something goes wrong.
|
||||
*
|
||||
* @internal param string $source_assets_directory the full path to the source asstes directory
|
||||
* @internal param string $web_assets_directory_base the base directory of the web based asset directory
|
||||
* @internal param string $key the assets key : module name or 0 for base template
|
||||
*/
|
||||
public function prepareAssets($source_assets_directory, $web_assets_directory_base);
|
||||
public function prepareAssets($sourceAssetsDirectory, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey);
|
||||
|
||||
/**
|
||||
* Generates assets from $asset_path in $output_path, using $filters.
|
||||
*
|
||||
* @param string $asset_path the full path to the asset file (or file collection, e.g. *.less)
|
||||
* @param $assetSource
|
||||
* @param $assetDirectoryBase
|
||||
* @param string $webAssetsDirectoryBase the full path to the asset file (or file collection, e.g. *.less)
|
||||
*
|
||||
* @param string $web_assets_directory_base the full disk path to the base assets output directory in the web space
|
||||
* @param string $output_url the URL to the base assets output directory in the web space
|
||||
* @param string $webAssetsTemplate the full disk path to the base assets output directory in the web space
|
||||
* @param $webAssetsKey
|
||||
* @param string $outputUrl the URL to the base assets output directory in the web space
|
||||
*
|
||||
* @param string $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
||||
* @param array $filters a list of filters, as defined below (see switch($filter_name) ...)
|
||||
* @param string $assetType the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
||||
* @param array $filters a list of filters, as defined below (see switch($filter_name) ...)
|
||||
*
|
||||
* @param boolean $debug the debug mode, true or false
|
||||
* @param boolean $debug true / false
|
||||
*
|
||||
* @throws \InvalidArgumentException if an invalid filter name is found
|
||||
* @return string The URL to the generated asset file.
|
||||
* @internal param string $web_assets_directory_base the full disk path to the base assets output directory in the web space
|
||||
* @internal param string $output_url the URL to the base assets output directory in the web space
|
||||
*
|
||||
* @return string The URL to the generated asset file.
|
||||
*/
|
||||
public function processAsset($asset_path, $web_assets_directory_base, $output_url, $asset_type, $filters, $debug);
|
||||
public function processAsset($assetSource, $assetDirectoryBase, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
@@ -17,7 +17,7 @@
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
@@ -31,7 +31,6 @@ use Assetic\AssetWriter;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Log\Tlog;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
|
||||
/**
|
||||
* This class is a simple helper for generating assets using Assetic.
|
||||
@@ -52,7 +51,7 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
/**
|
||||
* Create a stamp form the modification time of the content of the given directory and all of its subdirectories
|
||||
*
|
||||
* @param string $directory ther directory name
|
||||
* @param string $directory ther directory name
|
||||
* @return string the stamp of this directory
|
||||
*/
|
||||
protected function getStamp($directory)
|
||||
@@ -73,19 +72,21 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
/**
|
||||
* Check if a file is a source asset file
|
||||
*
|
||||
* @param \DirectoryIterator $fileInfo
|
||||
* @param \SplFileInfo $fileInfo
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isSourceFile(\SplFileInfo $fileInfo)
|
||||
{
|
||||
protected function isSourceFile(\SplFileInfo $fileInfo) {
|
||||
return in_array($fileInfo->getExtension(), $this->source_file_extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively copy assets from the source directory to the destination
|
||||
* directory in the web space, ommiting source files.
|
||||
* directory in the web space, omitting source files.
|
||||
*
|
||||
* @param string $from_directory the source
|
||||
* @param string $to_directory the destination
|
||||
* @param Filesystem $fs
|
||||
* @param string $from_directory the source
|
||||
* @param string $to_directory the destination
|
||||
* @throws \RuntimeException if a problem occurs.
|
||||
*/
|
||||
protected function copyAssets(Filesystem $fs, $from_directory, $to_directory)
|
||||
@@ -122,38 +123,21 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compite the assets path relative to the base template directory
|
||||
*
|
||||
* @param string $source_assets_directory the source directory
|
||||
* @param string $web_assets_directory_base base directory of the web assets
|
||||
* @return the full path of the destination directory
|
||||
*/
|
||||
protected function getRelativeDirectoryPath($source_assets_directory, $web_assets_directory_base)
|
||||
{
|
||||
$source_assets_directory = realpath($source_assets_directory);
|
||||
|
||||
// Remove base path from asset source path to get a path relative to the template base
|
||||
// and use it to create the destination path.
|
||||
return str_replace(
|
||||
realpath(THELIA_ROOT),
|
||||
'',
|
||||
$source_assets_directory
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the destination directory path, from the source directory and the
|
||||
* base directory of the web assets
|
||||
*
|
||||
* @param string $source_assets_directory the source directory
|
||||
* @param string $web_assets_directory_base base directory of the web assets
|
||||
* @return the full path of the destination directory
|
||||
* @param string $webAssetsDirectoryBase base directory of the web assets
|
||||
* @param $webAssetsTemplate
|
||||
* @param string $webAssetsKey the assests key : module name or 0 for base template
|
||||
*
|
||||
* @internal param string $source_assets_directory the source directory
|
||||
* @return the full path of the destination directory
|
||||
*/
|
||||
protected function getDestinationDirectory($source_assets_directory, $web_assets_directory_base)
|
||||
protected function getDestinationDirectory($webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey)
|
||||
{
|
||||
// Compute the absolute path of the output directory
|
||||
return $web_assets_directory_base . $this->getRelativeDirectoryPath($source_assets_directory, $web_assets_directory_base);
|
||||
return $webAssetsDirectoryBase . DS . $webAssetsTemplate . DS . $webAssetsKey;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,14 +145,17 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
* the source directory. If any change is detected, the whole asset directory
|
||||
* is copied in the web space.
|
||||
*
|
||||
* @param string $source_assets_directory the full path to the source asstes directory
|
||||
* @param string $web_assets_directory_base the base directory of the web based asset directory
|
||||
* @param string $sourceAssetsDirectory the full path to the source asstes directory
|
||||
* @param string $webAssetsDirectoryBase the base directory of the web based asset directory
|
||||
* @param $webAssetsTemplate
|
||||
* @param string $webAssetsKey the assets key : module name or 0 for base template
|
||||
*
|
||||
* @throws \RuntimeException if something goes wrong.
|
||||
*/
|
||||
public function prepareAssets($source_assets_directory, $web_assets_directory_base)
|
||||
public function prepareAssets($sourceAssetsDirectory, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey)
|
||||
{
|
||||
// Compute the absolute path of the output directory
|
||||
$to_directory = $this->getDestinationDirectory($source_assets_directory, $web_assets_directory_base);
|
||||
$to_directory = $this->getDestinationDirectory($webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey);
|
||||
|
||||
// Get a path to the stamp file
|
||||
$stamp_file_path = $to_directory . DS . '.source-stamp';
|
||||
@@ -177,7 +164,7 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
$prev_stamp = @file_get_contents($stamp_file_path);
|
||||
|
||||
// Get the current stamp of the source directory
|
||||
$curr_stamp = $this->getStamp($source_assets_directory);
|
||||
$curr_stamp = $this->getStamp($sourceAssetsDirectory);
|
||||
|
||||
if ($prev_stamp !== $curr_stamp) {
|
||||
|
||||
@@ -186,11 +173,11 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
// FIXME: locking or not locking ?
|
||||
/*
|
||||
$lock_file = "$web_assets_directory_base/assets-".md5($source_assets_directory)."-generation-lock.txt";
|
||||
|
||||
|
||||
if (! $fp = fopen($lock_file, "w")) {
|
||||
throw new IOException(sprintf('Failed to open lock file %s', $lock_file));
|
||||
}
|
||||
|
||||
|
||||
if (flock($fp, LOCK_EX|LOCK_NB)) { // do an exclusive lock
|
||||
*/
|
||||
$tmp_dir = "$to_directory.tmp";
|
||||
@@ -198,7 +185,7 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
$fs->remove($tmp_dir);
|
||||
|
||||
// Copy the whole source dir in a temp directory
|
||||
$this->copyAssets($fs, $source_assets_directory, $tmp_dir);
|
||||
$this->copyAssets($fs, $sourceAssetsDirectory, $tmp_dir);
|
||||
|
||||
// Remove existing directory
|
||||
if ($fs->exists($to_directory)) $fs->remove($to_directory);
|
||||
@@ -208,17 +195,18 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
/*
|
||||
// Release the lock
|
||||
flock($fp, LOCK_UN);
|
||||
|
||||
|
||||
// Remove the lock file
|
||||
@fclose($fp);
|
||||
|
||||
|
||||
$fs->remove($lock_file);
|
||||
*/
|
||||
if (false === @file_put_contents($stamp_file_path, $curr_stamp)) {
|
||||
throw new \RuntimeException(
|
||||
"Failed to create asset stamp file $stamp_file_path. Please check that your web server has the proper access rights to do that.");
|
||||
}
|
||||
/* } else {
|
||||
/* }
|
||||
else {
|
||||
@fclose($fp);
|
||||
}
|
||||
*/
|
||||
@@ -228,13 +216,13 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
/**
|
||||
* Decode the filters names, and initialize the Assetic FilterManager
|
||||
*
|
||||
* @param FilterManager $filterManager the Assetic filter manager
|
||||
* @param string $filters a comma separated list of filter names
|
||||
* @param FilterManager $filterManager the Assetic filter manager
|
||||
* @param string $filters a comma separated list of filter names
|
||||
* @throws \InvalidArgumentException if a wrong filter is passed
|
||||
* @return an array of filter names
|
||||
* @return an array of filter names
|
||||
*/
|
||||
protected function decodeAsseticFilters(FilterManager $filterManager, $filters)
|
||||
{
|
||||
protected function decodeAsseticFilters(FilterManager $filterManager, $filters) {
|
||||
|
||||
if (!empty($filters)) {
|
||||
|
||||
$filter_list = explode(',', $filters);
|
||||
@@ -273,7 +261,8 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$filter_list = array();
|
||||
}
|
||||
|
||||
@@ -283,67 +272,73 @@ class AsseticAssetManager implements AssetManagerInterface
|
||||
/**
|
||||
* Generates assets from $asset_path in $output_path, using $filters.
|
||||
*
|
||||
* @param string $asset_path the full path to the asset file (or file collection, e.g. *.less)
|
||||
* @param $assetSource
|
||||
* @param $assetDirectoryBase
|
||||
* @param string $webAssetsDirectoryBase the full path to the asset file (or file collection, e.g. *.less)
|
||||
*
|
||||
* @param string $web_assets_directory_base the full disk path to the base assets output directory in the web space
|
||||
* @param string $output_url the URL to the base assets output directory in the web space
|
||||
* @param string $webAssetsTemplate the full disk path to the base assets output directory in the web space
|
||||
* @param $webAssetsKey
|
||||
* @param string $outputUrl the URL to the base assets output directory in the web space
|
||||
*
|
||||
* @param string $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
||||
* @param array $filters a list of filters, as defined below (see switch($filter_name) ...)
|
||||
* @param string $assetType the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
||||
* @param array $filters a list of filters, as defined below (see switch($filter_name) ...)
|
||||
*
|
||||
* @param boolean $debug true / false
|
||||
* @throws \InvalidArgumentException if an invalid filter name is found
|
||||
* @return string The URL to the generated asset file.
|
||||
* @param boolean $debug true / false
|
||||
*
|
||||
* @return string The URL to the generated asset file.
|
||||
*/
|
||||
public function processAsset($asset_path, $web_assets_directory_base, $output_url, $asset_type, $filters, $debug)
|
||||
public function processAsset($assetSource, $assetDirectoryBase, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug)
|
||||
{
|
||||
$asset_name = basename($asset_path);
|
||||
$input_directory = realpath(dirname($asset_path));
|
||||
$assetName = basename($assetSource);
|
||||
$inputDirectory = realpath(dirname($assetSource));
|
||||
|
||||
$assetFileDirectoryInAssetDirectory = trim(str_replace(array($assetDirectoryBase, $assetName), '', $assetSource), DS);
|
||||
|
||||
$am = new AssetManager();
|
||||
$fm = new FilterManager();
|
||||
|
||||
// Get the filter list
|
||||
$filter_list = $this->decodeAsseticFilters($fm, $filters);
|
||||
$filterList = $this->decodeAsseticFilters($fm, $filters);
|
||||
|
||||
// Factory setup
|
||||
$factory = new AssetFactory($input_directory);
|
||||
$factory = new AssetFactory($inputDirectory);
|
||||
|
||||
$factory->setAssetManager($am);
|
||||
$factory->setFilterManager($fm);
|
||||
|
||||
$factory->setDefaultOutput('*' . (!empty($asset_type) ? '.' : '') . $asset_type);
|
||||
$factory->setDefaultOutput('*' . (!empty($assetType) ? '.' : '') . $assetType);
|
||||
|
||||
$factory->setDebug($debug);
|
||||
|
||||
$asset = $factory->createAsset($asset_name, $filter_list);
|
||||
$asset = $factory->createAsset($assetName, $filterList);
|
||||
|
||||
$input_directory = realpath(dirname($asset_path));
|
||||
|
||||
$output_directory = $this->getDestinationDirectory($input_directory, $web_assets_directory_base);
|
||||
$outputDirectory = $this->getDestinationDirectory($webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey);
|
||||
|
||||
// Get the URL part from the relative path
|
||||
$output_relative_path = $this->getRelativeDirectoryPath($input_directory, $web_assets_directory_base);
|
||||
$outputRelativePath = $webAssetsTemplate . DS . $webAssetsKey;
|
||||
|
||||
$output_relative_web_path = rtrim(str_replace('\\', '/', $output_relative_path), '/') . '/';
|
||||
$outputRelativeWebPath = rtrim(str_replace('\\', '/', $outputRelativePath), '/') . '/';
|
||||
|
||||
$asset_target_filename = $asset->getTargetPath();
|
||||
$assetTargetFilename = $asset->getTargetPath();
|
||||
|
||||
// This is the final name of the generated asset
|
||||
$asset_destination_path = $output_directory . DS . $asset_target_filename;
|
||||
/*
|
||||
* This is the final name of the generated asset
|
||||
* We preserve file structure intending to keep - for example - relative css links working
|
||||
*/
|
||||
$assetDestinationPath = $outputDirectory . DS . $assetFileDirectoryInAssetDirectory . DS . $assetTargetFilename;
|
||||
|
||||
Tlog::getInstance()->addDebug("Asset destination full path: $asset_destination_path");
|
||||
Tlog::getInstance()->addDebug("Asset destination full path: $assetDestinationPath");
|
||||
|
||||
// We generate an asset only if it does not exists, or if the asset processing is forced in development mode
|
||||
if (! file_exists($asset_destination_path) || ($this->debugMode && ConfigQuery::read('process_assets', true)) ) {
|
||||
if (! file_exists($assetDestinationPath) || ($this->debugMode && ConfigQuery::read('process_assets', true)) ) {
|
||||
|
||||
$writer = new AssetWriter($output_directory);
|
||||
$writer = new AssetWriter($outputDirectory . DS . $assetFileDirectoryInAssetDirectory);
|
||||
|
||||
Tlog::getInstance()->addDebug("Writing asset to $output_directory");
|
||||
Tlog::getInstance()->addDebug("Writing asset to $outputDirectory . DS . $assetFileDirectoryInAssetDirectory");
|
||||
|
||||
$writer->writeAsset($asset);
|
||||
}
|
||||
|
||||
return rtrim($output_url, '/') . '/' . ltrim($output_relative_web_path, '/') . $asset_target_filename;
|
||||
return rtrim($outputUrl, '/') . '/' . trim($outputRelativeWebPath, '/') . '/' . trim($assetFileDirectoryInAssetDirectory, '/') . '/' . ltrim($assetTargetFilename, '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,21 +91,20 @@ class OrderCoupon extends BaseLoop implements PropelSearchLoopInterface
|
||||
|
||||
$cleanedConditions = array();
|
||||
|
||||
foreach ($conditions->getConditions() as $condition) {
|
||||
/*foreach ($conditions->getConditions() as $condition) {
|
||||
$cleanedConditions[] = $condition->getToolTip();
|
||||
}
|
||||
}*/
|
||||
$loopResultRow->set("ID", $orderCoupon->getId())
|
||||
->set("CODE", $orderCoupon->getCode())
|
||||
->set("TITLE", $orderCoupon->getTitle())
|
||||
->set("SHORT_DESCRIPTION", $orderCoupon->getShortDescription())
|
||||
->set("DESCRIPTION", $orderCoupon->getDescription())
|
||||
->set("EXPIRATION_DATE", $orderCoupon->getExpirationDate( OrderQuery::create()->findPk($this->getOrder())->getLangId() ))
|
||||
->set("USAGE_LEFT", $orderCoupon->getMaxUsage())
|
||||
->set("IS_CUMULATIVE", $orderCoupon->getIsCumulative())
|
||||
->set("IS_REMOVING_POSTAGE", $orderCoupon->getIsRemovingPostage())
|
||||
->set("IS_AVAILABLE_ON_SPECIAL_OFFERS", $orderCoupon->getIsAvailableOnSpecialOffers())
|
||||
->set("AMOUNT", $orderCoupon->getAmount())
|
||||
->set("APPLICATION_CONDITIONS", $cleanedConditions)
|
||||
//->set("AMOUNT", $orderCoupon->getAmount())
|
||||
//->set("APPLICATION_CONDITIONS", $cleanedConditions)
|
||||
->set("DAY_LEFT_BEFORE_EXPIRATION", $daysLeftBeforeExpiration)
|
||||
;
|
||||
$loopResult->addRow($loopResultRow);
|
||||
|
||||
Reference in New Issue
Block a user