venveo / craft-compress Goto Github PK
View Code? Open in Web Editor NEWAutomatically compress asset queries into zip files
Home Page: https://www.venveo.com/
License: MIT License
Automatically compress asset queries into zip files
Home Page: https://www.venveo.com/
License: MIT License
Would love the ability to compress with a folder structure... perhaps denoted by an array, i.e.:
{% set zip = {
"folderName1": { assetIdArray },
"folderName2": { assetIdArray }
} %}
So that when the zip is opened/uncompressed it has files within the denoted folders.
Thanks!
instead of only AssetQuery
/ ArrayAccess
.
while craft.compress.zip(assets, true, 'asdf')
works as advertised, I am running into problems when trying to call getArchiveModelForQuery
from my custom module.
Event::on(
OrderHistories::class,
OrderHistories::EVENT_ORDER_STATUS_CHANGE,
function(OrderStatusEvent $event) {
// [...]
$query = utils\getOrderAssetsQuery($order);
$compress = Compress::getInstance()->compress;
$lazy = false;
$name = $order->reference;
$zipAsset = $compress->getArchiveModelForQuery($query, $lazy, $name);
}
);
looks like https://github.com/venveo/craft-compress/blob/main/src/services/Compress.php#L183 fails because the temp file does not exist.
log:
[web.ERROR] [venveo\compress\services\Compress::getArchiveModelForQuery] fopen(/var/www/html/storage/runtime/temp/compress/50a433ce-4676-4196-ba79-b9ff80cbc221.zip): Failed to open stream: No such file or directory {"memory":13510432}
Not going to work on this until someone says it's an issue ;)
System check would look at your server to determine possible issues, such as lack of memory or extensions
The plugin should provide an option to index the filenames in an archive
I have used your plugin before on another site and loved it! I am trying to add it to a new site using the same HTML/twig code and settings, but am running into trouble with producing the zip file. After troubleshooting, I have found that the array of file ids is being created, and is being added to: {% set zipAssets = craft.assets().volume('compress').document(filesArray) %}. I believe the problem starts when I set the archive. The JSON I am getting from the archive has all of the keys filled out except for assetId and asset (both have null values). I am guessing these are null because the asset is not being created correctly at this stage? I am still getting a url from the archiveAsset, but when I follow it I get a 404 error. My Queue Manager says that the action has failed and allows me to retry, but this doesn't work, and my Compress Cache is saying that the logged run has assets that are "Not Ready".
My storage/logs are telling me that the system is "Creating Archive" but is quickly followed by "Failed to create archive", but then continues trying to open the nonexistent zip: "Failed to open stream: No such file or directory". So it seems like it is trying, but the failure is in the archive.
If you know why this is happening, are there any settings or extra code I should be using to counter this issue? As I've said before, I have used the plugin on another site with almost the exact same code and settings, and both sites reside within the same AWS account, so Im not sure what could be going wrong in those areas as they are too similar and should be acting similarly. I have also updated to the most recent version of craft on both websites where I am utilizing this plugin, so I dont suspect it has anything to do with that.
My Code:
{% set zipAssets = craft.assets().volume('compress').id(filesArray) %}
{% set archive = craft.compress.zip(zipAssets, true, event.title ~ ' - Event Files') %}
{% set archiveAsset = archive.isReady ? archive.getAsset().getUrl() : archive.lazyLink %}
<a href="{{ archiveAsset }}" target="_blank" class="button">
<i class="fa-solid fa-arrow-down-to-line prependedIcon"></i>Download all files (.zip)
</a>
Currently limited to just showing the last 100 archives. When 3.4 comes out, this should be switched to the Vue Admin Table component.
Would like to add:
Would be nice to be able to parse zip files in twig, such as getting the contents. Compress would cache this for you.
In Craft 3.2.10 with PHP 7.0.33 in local dev, I have a custom module that deletes assets associated with an entry when I delete the entry in either front or back end. When the Compress plugin is enabled, I can no longer delete the asset and get following error on front end:
TypeError
Return value of venveo\compress\services\Compress::handleAssetUpdated() must be an instance of venveo\compress\services\void, none returned
1. in /home/vagrant/sites/lccphoto/vendor/venveo/craft-compress/src/services/Compress.php at line 314
305306307308309310311312313314315316317318319320321322323
]);
$jobId = Craft::$app->queue->push($job);
Craft::$app->cache->set($cacheKey, true);
Craft::$app->cache->set($cacheKey . ':' . 'jobId', $jobId);
Craft::info('Regenerating archive after a file was deleted.', __METHOD__);
}
}
}
}
/**
* @param ArchiveModel $archive
* @return AssetQuery
*/
public function getArchiveContents(ArchiveModel $archive): AssetQuery
{
$records = FileRecord::find()->where(['=', 'archiveId', $archive->id])->select(['assetId'])->asArray()->all();
// There has to be a better way to do this...
2. in /home/vagrant/sites/lccphoto/vendor/venveo/craft-compress/src/Compress.php at line 86 โ venveo\compress\services\Compress::handleAssetUpdated(craft\elements\Asset)
80818283848586878889909192
Event::on(
Asset::class,
Asset::EVENT_BEFORE_DELETE,
function (ModelEvent $event) {
/** @var Asset $asset */
$asset = $event->sender;
$this->compress->handleAssetUpdated($asset);
}
);
Event::on(
Asset::class,
Asset::EVENT_AFTER_SAVE,
Screenshot: https://cl.ly/18dc11babe5b
If I change public function handleAssetUpdated(Asset $asset): void
to public function handleAssetUpdated(Asset $asset)
in services/Compress.php
, the error goes away and all works as expected. From what I can tell, void
is PHP 7.1+ feature.
Also, when I was running PHP 7.1 in local dev yesterday, I didn't get this error in my tests.
Many thanks!
Hello,
i am using the plugin vor craft cms v3 and try to generate zip files with custom filenames, but i always get <UID>.zip
This twig code
craft.compress.zip(assets, true, filename)
calls later on in src/services/Compress.php:104
$this->createArchiveAsset($record, $filename);
but in src/services/Compress.php:127
public function createArchiveAsset(ArchiveRecord $archiveRecord)
the filename parameter is ignored.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.