Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Fixed php error. Added logging on plugin level. Added console commmand.
Browse files Browse the repository at this point in the history
  • Loading branch information
roelvanhintum committed May 4, 2018
1 parent d7a92fc commit 2cbbcdc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
5 changes: 5 additions & 0 deletions ColorExtractorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public function getName()
}

public function getVersion()
{
return '1.0.6';
}

public function getSchemaVersion()
{
return '1.0.5';
}
Expand Down
16 changes: 16 additions & 0 deletions consolecommands/ColorextractorCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Colorextractor Command
*
* ./craft/app/etc/console/yiic colorextractor
*/

namespace Craft;

class ColorextractorCommand extends BaseCommand
{
public function actionIndex()
{
craft()->colorExtractor_assetUpload->processImages();
}
}
10 changes: 10 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[
{
"version": "1.0.6",
"downloadUrl": "https://github.com/born05/craft-colorextractor/archive/1.0.6.zip",
"date": "2018-05-4T11:00:00+00:00",
"notes": [
"Fixed php error.",
"Added logging on plugin level",
"Added console commmand"
]
},
{
"version": "1.0.5",
"downloadUrl": "https://github.com/born05/craft-colorextractor/archive/1.0.5.zip",
Expand Down
7 changes: 6 additions & 1 deletion services/ColorExtractor_AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ public function getImageColor(AssetFileModel $asset, $forceSave = false)

// Only Extract color when forced.
if ($forceSave) {
$color = $this->extractColor($asset);
try {
$color = $this->extractColor($asset);
} catch (Exception $e) {
ColorExtractorPlugin::log($e->getMessage(), LogLevel::Error, true);
return false;
}

$asset->getContent()->setAttribute('imageColor', $color);
$success = craft()->assets->storeFile($asset);
Expand Down
5 changes: 3 additions & 2 deletions services/ColorExtractor_AssetUploadService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function processImages()
{
$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->kind = 'image';
$criteria->imageColor = ':empty:';
$criteria->limit = null;
$assetIds = $criteria->ids();

Expand All @@ -42,9 +43,9 @@ public function processImages()

/**
* Create task
* @param string|array $ids
* @param string|array $assetIds
*/
private function createTask($ids)
private function createTask($assetIds)
{
if (!is_array($assetIds)) {
$assetIds = [$assetIds];
Expand Down
6 changes: 1 addition & 5 deletions tasks/ColorExtractor_ExtactTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ public function runStep($step)
$assetModel = $criteria->first();

if (isset($assetModel)) {
try {
craft()->colorExtractor_asset->getImageColor($assetModel, true);
} catch (Exception $e) {
return false;
}
craft()->colorExtractor_asset->getImageColor($assetModel, true);
}

return true;
Expand Down

0 comments on commit 2cbbcdc

Please sign in to comment.