Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Provides a visual icon picker for content authors. Icon files are managable via

# Requirements

- SilverStripe 4 or 5
- Silverstripe CMS 6
- For Silverstripe CMS 4 and 5, see previous releases

# Version
- Use release 1 for legacy non-cms editable icon files
Expand Down Expand Up @@ -54,6 +55,3 @@ PlasticStudio\IconField\IconField:
default_height: "30"

```



4 changes: 2 additions & 2 deletions code/IconField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use DirectoryIterator;
use SilverStripe\Core\Path;
use SilverStripe\Assets\Folder;
use SilverStripe\ORM\ArrayList;
use SilverStripe\View\ArrayData;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\Model\ArrayData;
use SilverStripe\Forms\FormField;
use SilverStripe\View\Requirements;
use SilverStripe\Core\Config\Config;
Expand Down
34 changes: 17 additions & 17 deletions code/IconFieldPathMigrator_Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ class IconFieldPathMigrator_BuildTask extends BuildTask

protected string $title = 'Update icon file paths to assets folder';
protected bool $enabled = true;

protected function execute(InputInterface $input, PolyOutput $output): int
{
// Get query parameters (supports both CLI & HTTP dev/tasks)
$vars = $_GET ?? [];

if (!isset($vars['classname']) || !isset($vars['field'])) {
$output->writeLine('Pass both class and field in the query string, eg ?classname=Skeletor\DataObjects\SummaryPanel&field=SVGIcon');
$output->writeLine('If new folder is not "SiteIcons", pass new-path in the query string, eg &new-path=NewFolder');
$output->writeLine('Classname must include namespace');
$output->writeForHtml('Pass both class and field in the query string, eg ?classname=Skeletor\DataObjects\SummaryPanel&field=SVGIcon', true);
$output->writeForHtml('If new folder is not "SiteIcons", pass new-path in the query string, eg &new-path=NewFolder', true);
$output->writeForHtml('Classname must include namespace', true);
return 1;
}

Expand All @@ -39,23 +39,23 @@ protected function execute(InputInterface $input, PolyOutput $output): int
$folderPath = isset($vars['new-path']) ? 'assets/' . $vars['new-path'] : 'assets/SiteIcons';

if (!ClassInfo::exists($classname)) {
$output->writeLine("Class {$classname} does not exist. Make sure to include namespace.");
$output->writeForHtml("Class {$classname} does not exist. Make sure to include namespace.", true);
return 1;
}

$objects = $classname::get();
$schema = DataObject::getSchema();

if (!$schema->classHasTable($classname)) {
$output->writeLine("Class {$classname} does not have a database table.");
$output->writeForHtml("Class {$classname} does not have a database table.");
return 1;
}

$tableName = Convert::raw2sql($schema->tableName($classname));
$iconCol = Convert::raw2sql($iconField);

if (!$objects || !$tableName) {
$output->writeLine("No objects found for class {$classname}");
$output->writeForHtml("No objects found for class {$classname}", true);
return 0;
}

Expand All @@ -66,42 +66,42 @@ protected function execute(InputInterface $input, PolyOutput $output): int
$originIconName = basename($originIconPath);
$newIconPath = $folderPath . '/' . $originIconName;

$output->writeLine("Updating {$object->Title}");
$output->writeLine("Origin: {$originIconPath}");
$output->writeLine("New path: {$newIconPath}");
$output->writeForHtml("Updating {$object->Title}", true);
$output->writeForHtml("Origin: {$originIconPath}", true);
$output->writeForHtml("New path: {$newIconPath}", true);

DB::prepared_query(
"UPDATE {$tableName} SET {$iconCol} = ? WHERE ID = ?",
[$newIconPath, $object->ID]
);
$output->writeLine("{$tableName} updated");
$output->writeForHtml("{$tableName} updated", true);

if ($object->hasExtension(Versioned::class)) {
$tableNameVersioned = $tableName . '_Versions';
DB::prepared_query(
"UPDATE {$tableNameVersioned} SET {$iconCol} = ? WHERE RecordID = ?",
[$newIconPath, $object->ID]
);
$output->writeLine("{$tableNameVersioned} updated");
$output->writeForHtml("{$tableNameVersioned} updated", true);

if ($object->isPublished()) {
$tableNameLive = $tableName . '_Live';
DB::prepared_query(
"UPDATE {$tableNameLive} SET {$iconCol} = ? WHERE ID = ?",
[$newIconPath, $object->ID]
);
$output->writeLine("{$tableNameLive} updated");
$output->writeForHtml("{$tableNameLive} updated", true);
}
}

$output->writeLine("Panel icon updated");
$output->writeForHtml("Panel icon updated", true);
} else {
$output->writeLine("{$object->Title} - No icon, skipped");
$output->writeForHtml("{$object->Title} - No icon, skipped", true);
}

$output->writeLine("-------");
$output->writeForHtml("-------", true);
}

return 0;
}
}
}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
]
},
"require": {
"silverstripe/cms": "^4 || ^5 || ^6",
"silverstripe/framework": "^4 || ^5 || ^6",
"silverstripe/vendor-plugin": "^1 || ^2 || ^3"
"silverstripe/cms": "^6",
"silverstripe/framework": "^6",
"silverstripe/vendor-plugin": "^3"
},
"minimum-stability": "dev"
}