Git Product home page Git Product logo

craft-compress's People

Contributors

jrm98 avatar mosnar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

freder qrazi

craft-compress's Issues

FR: Folder Structure

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!

Fails when trying to call from a custom Craft module

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}

Failed to create archive, after successfully creating array of files

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>

Improve UI of utility page

Currently limited to just showing the last 100 archives. When 3.4 comes out, this should be switched to the Vue Admin Table component.

Add helpers for zip files

Would be nice to be able to parse zip files in twig, such as getting the contents. Compress would cache this for you.

TypeError: Return value of venveo\compress\services\Compress::handleAssetUpdated() must be an instance of venveo\compress\services\void, none returned

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!

filename parameter is not used

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.