Skip to content

Commit

Permalink
Merge pull request #51 from enupal/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
andrelopez authored May 21, 2022
2 parents fd32f19 + dc78fed commit a9fb13b
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Enupal Snapshot Changelog

## 2.0.0 - 2022.05.21

### Added
- Added Craft CMS 4 support

## 1.2.8 - 2020.07.02
### Added
- Added `autosuggestField` to the Stripe Payments Order PDF Template setting
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img width="212" height="212" src="https://enupal.com/assets/docs/snapshot-icon.svg" alt="Enupal Snapshot"></a>
</p>

# Enupal Snapshot Plugin for Craft CMS 3.x
# Enupal Snapshot Plugin for Craft CMS

PDF or Image generation from a URL or HTML page easily. It uses the excellent webkit-based wkhtmltopdf and wkhtmltoimage available on OSX, Linux & windows.
## Features
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "enupal/snapshot",
"description": "PDF or Image generation from a Url or HTML page",
"type": "craft-plugin",
"version": "1.2.8",
"version": "2.0.0",
"keywords": [
"craft",
"cms",
Expand All @@ -24,7 +24,7 @@
}
],
"require": {
"craftcms/cms": "^3.1.0",
"craftcms/cms": "^4.0.0",
"knplabs/knp-snappy": "^1.0"
},
"autoload": {
Expand Down
12 changes: 6 additions & 6 deletions src/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ class Snapshot extends Plugin
/**
* @inheritdoc
*/
public $schemaVersion = '1.2.0';
public string $schemaVersion = '2.0.0';

/**
* @inheritdoc
*/
public $hasCpSection = false;
public bool $hasCpSection = false;

/**
* @inheritdoc
*/
public $hasCpSettings = true;
public bool $hasCpSettings = true;

/**
* @inheritdoc
Expand Down Expand Up @@ -133,15 +133,15 @@ function(Event $event) {
/**
* @inheritdoc
*/
protected function createSettingsModel()
protected function createSettingsModel(): ?\craft\base\Model
{
return new Settings();
}

/**
* @inheritdoc
*/
protected function settingsHtml(): string
protected function settingsHtml(): ?string
{
return Craft::$app->view->renderTemplate(
'enupal-snapshot/settings',
Expand Down Expand Up @@ -191,7 +191,7 @@ private function isStripePaymentsInstalled()
{
$stripePluginHandle = 'enupal-stripe';
$projectConfig = Craft::$app->getProjectConfig();
$stripePaymentsSettings = $projectConfig->get(Plugins::CONFIG_PLUGINS_KEY.'.'.$stripePluginHandle);
$stripePaymentsSettings = $projectConfig->get(\craft\services\ProjectConfig::PATH_PLUGINS.'.'.$stripePluginHandle);
$isInstalled = $stripePaymentsSettings['enabled'] ?? false;

return $isInstalled;
Expand Down
29 changes: 15 additions & 14 deletions src/contracts/BaseSnappy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

use Craft;
use craft\elements\Asset;
use craft\errors\AssetException;
use craft\errors\InvalidSubpathException;
use craft\errors\InvalidVolumeException;
use craft\helpers\UrlHelper;
use enupal\snapshot\models\Settings;
use enupal\snapshot\Snapshot;
Expand Down Expand Up @@ -174,9 +174,9 @@ public function getSettings(SnappySettings $settings, $isPdf = true): SnappySett
}

if (!$isValidFileName) {
$info = Craft::$app->getInfo();
$primarySite = Craft::$app->getSites()->getPrimarySite();
$systemName = FileHelper::sanitizeFilename(
$info->name,
$primarySite->getName(),
[
'asciiOnly' => true,
'separator' => '_'
Expand All @@ -202,7 +202,7 @@ public function getSettings(SnappySettings $settings, $isPdf = true): SnappySett
* @param SnappySettings $settingsModel
* @return Asset
* @throws InvalidSubpathException
* @throws InvalidVolumeException
* @throws AssetException
* @throws \Throwable
* @throws \craft\errors\ElementNotFoundException
* @throws \craft\errors\VolumeException
Expand Down Expand Up @@ -311,7 +311,7 @@ public function getStripePaymentsFilename($settings, $isPdf = true)
* @param SnappySettings $settingsModel
* @return array|\craft\base\ElementInterface|Asset|null
* @throws InvalidSubpathException
* @throws InvalidVolumeException
* @throws AssetException
* @throws \craft\errors\VolumeException
*/
public function getAssetIfFileExists($settingsModel)
Expand All @@ -333,7 +333,7 @@ public function getAssetIfFileExists($settingsModel)
* @param SnappySettings $settingsModel
* @return int
* @throws InvalidSubpathException if the folder subpath is not valid
* @throws InvalidVolumeException if there's a problem with the field's volume configuration
* @throws AssetException if there's a problem with the field's volume configuration
* @throws \craft\errors\VolumeException
*/
private function determineUploadFolderId($settingsModel): int
Expand All @@ -354,11 +354,11 @@ private function determineUploadFolderId($settingsModel): int

try {
if (!$uploadVolume) {
throw new InvalidVolumeException();
throw new AssetException();
}
$folderId = $this->resolveVolumePathToFolderId($uploadVolume, $subpath);
} catch (InvalidVolumeException $e) {
throw new InvalidVolumeException(Craft::t('app', '{setting} setting is set to an invalid volume.', [
} catch (AssetException $e) {
throw new AssetException(Craft::t('app', '{setting} setting is set to an invalid volume.', [
'setting' => $settingName,
]), 0, $e);
} catch (InvalidSubpathException $e) {
Expand All @@ -379,7 +379,7 @@ private function determineUploadFolderId($settingsModel): int
* @param string $subpath
* @return int
* @throws InvalidSubpathException
* @throws InvalidVolumeException if the volume root folder doesn’t exist
* @throws AssetException if the volume root folder doesn’t exist
* @throws \craft\errors\VolumeException
*/
private function resolveVolumePathToFolderId(string $uploadSource, string $subpath): int
Expand All @@ -390,7 +390,7 @@ private function resolveVolumePathToFolderId(string $uploadSource, string $subpa

// Make sure the volume and root folder actually exists
if ($volumeId === null || ($rootFolder = $assetsService->getRootFolderByVolumeId($volumeId)) === null) {
throw new InvalidVolumeException();
throw new AssetException();
}

// Are we looking for a subfolder?
Expand Down Expand Up @@ -430,7 +430,8 @@ private function resolveVolumePathToFolderId(string $uploadSource, string $subpa

if (!$folder) {
$volume = Craft::$app->getVolumes()->getVolumeById($volumeId);
$folderId = $assetsService->ensureFolderByFullPathAndVolume($subpath, $volume);
$folder = $assetsService->ensureFolderByFullPathAndVolume($subpath, $volume);
$folderId = $folder->id;
} else {
$folderId = $folder->id;
}
Expand All @@ -453,9 +454,9 @@ public function volumeIdBySourceKey(string $sourceKey)
return null;
}

$folder = Craft::$app->getAssets()->getFolderByUid($parts[1]);
$volume = Craft::$app->getVolumes()->getVolumeByUid($parts[1]);

return $folder->volumeId ?? null;
return $volume->id ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/SnappyPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function displayUrl($url, $settings = null)
* @param array $options
*
* @return array
* @throws \Twig_Error_Loader
* @throws \Twig\Error\LoaderError
* @throws \yii\base\Exception
*/
public function getDefaultOptions($options = [])
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/m190123_000000_asset_setting_change.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function safeUp()
}

$projectConfig = Craft::$app->getProjectConfig();
$projectConfig->set(Plugins::CONFIG_PLUGINS_KEY . '.' . $plugin->handle . '.settings', $settings->toArray());
$projectConfig->set(\craft\services\ProjectConfig::PATH_PLUGINS . '.' . $plugin->handle . '.settings', $settings->toArray());

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Settings extends Model
/**
* @inheritdoc
*/
public function rules()
public function rules(): array
{
return [
[['pdfBinPath', 'imageBinPath'], 'required'],
Expand Down
2 changes: 1 addition & 1 deletion src/services/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class App extends Component
*/
public $settings;

public function init()
public function init(): void
{
$this->pdf = new Pdf();
$this->image = new Image();
Expand Down

0 comments on commit a9fb13b

Please sign in to comment.