Compare commits

...

4 Commits

Author SHA1 Message Date
Guy Sartorelli
23cb84ff00
API Update API to reflect changes to CLI interaction 2024-09-24 10:17:56 +12:00
Guy Sartorelli
a8306658aa
API Use new names for renamed classes (#600) 2024-09-23 14:38:38 +12:00
github-actions
9c50c27b24 Merge branch '3' into 4 2024-09-21 12:03:43 +00:00
Guy Sartorelli
9be525a902
ENH Don't use deprecated method (#601) 2024-09-19 13:42:46 +12:00
5 changed files with 70 additions and 34 deletions

View File

@ -14,7 +14,7 @@ use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Core\Extension; use SilverStripe\Core\Extension;
use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\HiddenField;
use SilverStripe\ORM\ArrayList; use SilverStripe\Model\List\ArrayList;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
@ -22,7 +22,7 @@ use SilverStripe\Security\Security;
use SilverStripe\Subsites\Controller\SubsiteXHRController; use SilverStripe\Subsites\Controller\SubsiteXHRController;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\State\SubsiteState; use SilverStripe\Subsites\State\SubsiteState;
use SilverStripe\View\ArrayData; use SilverStripe\Model\ArrayData;
use SilverStripe\View\Requirements; use SilverStripe\View\Requirements;
/** /**

View File

@ -15,12 +15,12 @@ use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormAction; use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\ToggleCompositeField; use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\i18n\i18n; use SilverStripe\i18n\i18n;
use SilverStripe\ORM\ArrayList; use SilverStripe\Model\List\ArrayList;
use SilverStripe\Core\Extension; use SilverStripe\Core\Extension;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataQuery; use SilverStripe\ORM\DataQuery;
use SilverStripe\ORM\ManyManyList; use SilverStripe\ORM\ManyManyList;
use SilverStripe\ORM\Map; use SilverStripe\Model\List\Map;
use SilverStripe\ORM\Queries\SQLSelect; use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;

View File

@ -18,12 +18,12 @@ use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\ToggleCompositeField; use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\i18n\Data\Intl\IntlLocales; use SilverStripe\i18n\Data\Intl\IntlLocales;
use SilverStripe\i18n\i18n; use SilverStripe\i18n\i18n;
use SilverStripe\ORM\ArrayLib; use SilverStripe\Core\ArrayLib;
use SilverStripe\ORM\ArrayList; use SilverStripe\Model\List\ArrayList;
use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\ORM\SS_List; use SilverStripe\Model\List\SS_List;
use SilverStripe\ORM\HasManyList; use SilverStripe\ORM\HasManyList;
use SilverStripe\ORM\ManyManyList; use SilverStripe\ORM\ManyManyList;
use SilverStripe\Security\Group; use SilverStripe\Security\Group;
@ -263,7 +263,7 @@ class Subsite extends DataObject
// ClassInfo::hasTable provides a cached table list // ClassInfo::hasTable provides a cached table list
if (!ClassInfo::hasTable($domainTableName)) { if (!ClassInfo::hasTable($domainTableName)) {
// Table hasn't been created yet. Might be a dev/build, skip. // Table hasn't been created yet. Might be bilding the db, skip.
return 0; return 0;
} }
@ -798,7 +798,7 @@ class Subsite extends DataObject
/** /**
* *
* @return \SilverStripe\ORM\ValidationResult * @return \SilverStripe\Core\Validation\ValidationResult
*/ */
public function validate() public function validate()
{ {

View File

@ -10,12 +10,12 @@ use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\ArrayList; use SilverStripe\Model\List\ArrayList;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\Subsites\Forms\SubsitesTreeDropdownField; use SilverStripe\Subsites\Forms\SubsitesTreeDropdownField;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\State\SubsiteState; use SilverStripe\Subsites\State\SubsiteState;
use SilverStripe\View\ArrayData; use SilverStripe\Model\ArrayData;
class SubsitesVirtualPage extends VirtualPage class SubsitesVirtualPage extends VirtualPage
{ {

View File

@ -2,14 +2,17 @@
namespace SilverStripe\Subsites\Tasks; namespace SilverStripe\Subsites\Tasks;
use InvalidArgumentException; use Closure;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\BuildTask; use SilverStripe\Dev\BuildTask;
use SilverStripe\Dev\Deprecation; use SilverStripe\PolyExecution\PolyOutput;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Pages\SubsitesVirtualPage; use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
/** /**
* Handy alternative to copying pages when creating a subsite through the UI. * Handy alternative to copying pages when creating a subsite through the UI.
@ -17,38 +20,43 @@ use SilverStripe\Versioned\Versioned;
* Can be used to batch-add new pages after subsite creation, or simply to * Can be used to batch-add new pages after subsite creation, or simply to
* process a large site outside of the UI. * process a large site outside of the UI.
* *
* Example: sake dev/tasks/SubsiteCopyPagesTask from=<subsite-source> to=<subsite-target> * Example: sake tasks:SubsiteCopyPagesTask --from=<subsite-source> --to=<subsite-target>
* *
* @package subsites * @package subsites
*/ */
class SubsiteCopyPagesTask extends BuildTask class SubsiteCopyPagesTask extends BuildTask
{ {
protected $title = 'Copy pages to different subsite'; protected string $title = 'Copy pages to different subsite';
protected $description = '';
private static $segment = 'SubsiteCopyPagesTask'; protected static string $description = 'Handy alternative to copying pages when creating a subsite through the UI';
public function run($request) protected static string $commandName = 'SubsiteCopyPagesTask';
protected function execute(InputInterface $input, PolyOutput $output): int
{ {
$subsiteFromId = $request->getVar('from'); $subsiteFromId = $input->getOption('from');
if (!is_numeric($subsiteFromId)) { if (!is_numeric($subsiteFromId)) {
throw new InvalidArgumentException('Missing "from" parameter'); $output->writeln('<error>Missing "from" parameter</>');
return Command::INVALID;
} }
$subsiteFrom = DataObject::get_by_id(Subsite::class, $subsiteFromId); $subsiteFrom = DataObject::get_by_id(Subsite::class, $subsiteFromId);
if (!$subsiteFrom) { if (!$subsiteFrom) {
throw new InvalidArgumentException('Subsite not found'); $output->writeln('<error>Subsite not found</>');
return Command::FAILURE;
} }
$subsiteToId = $request->getVar('to'); $subsiteToId = $input->getOption('to');
if (!is_numeric($subsiteToId)) { if (!is_numeric($subsiteToId)) {
throw new InvalidArgumentException('Missing "to" parameter'); $output->writeln('<error>Missing "to" parameter</>');
return Command::INVALID;
} }
$subsiteTo = DataObject::get_by_id(Subsite::class, $subsiteToId); $subsiteTo = DataObject::get_by_id(Subsite::class, $subsiteToId);
if (!$subsiteTo) { if (!$subsiteTo) {
throw new InvalidArgumentException('Subsite not found'); $output->writeln('<error>Subsite not found</>');
return Command::FAILURE;
} }
$useVirtualPages = (bool)$request->getVar('virtual'); $useVirtualPages = $input->getOption('virtual');
Subsite::changeSubsite($subsiteFrom); Subsite::changeSubsite($subsiteFrom);
@ -78,22 +86,50 @@ class SubsiteCopyPagesTask extends BuildTask
$childClone->copyVersionToStage('Stage', 'Live'); $childClone->copyVersionToStage('Stage', 'Live');
array_push($stack, [$child->ID, $childClone->ID]); array_push($stack, [$child->ID, $childClone->ID]);
Deprecation::withNoReplacement(function () use ($child) { $output->writeln(sprintf('Copied "%s" (#%d, %s)', $child->Title, $child->ID, $child->Link()));
$this->log(sprintf('Copied "%s" (#%d, %s)', $child->Title, $child->ID, $child->Link()));
});
} }
} }
unset($children); unset($children);
} }
return Command::SUCCESS;
} }
/** public function getOptions(): array
* @deprecated 3.4.0 Will be replaced with new $output parameter in the run() method
*/
public function log($msg)
{ {
Deprecation::notice('3.4.0', 'Will be replaced with new $output parameter in the run() method'); $subsiteSuggestionClosure = Closure::fromCallable([static::class, 'getSubsiteCompletion']);
echo $msg . "\n"; return [
new InputOption(
'from',
null,
InputOption::VALUE_REQUIRED,
'ID of the subsite to copy from',
suggestedValues: $subsiteSuggestionClosure
),
new InputOption(
'to',
null,
InputOption::VALUE_REQUIRED,
'ID of the subsite to copy to',
suggestedValues: $subsiteSuggestionClosure
),
new InputOption(
'virtual',
null,
InputOption::VALUE_NONE,
'Create virtual pages instead of duplicating pages'
),
];
}
public static function getSubsiteCompletion(): array
{
$subsites = Subsite::get()->map('ID', 'Title');
$suggestions = [];
foreach ($subsites as $id => $title) {
$suggestions[] = "{$id}\t{$title}";
}
return $suggestions;
} }
} }