Skip to content

Instantly share code, notes, and snippets.

@wsydney76
Created September 1, 2025 12:57
Show Gist options
  • Save wsydney76/bc59ea54117b74fe25d51644af1bef68 to your computer and use it in GitHub Desktop.
Save wsydney76/bc59ea54117b74fe25d51644af1bef68 to your computer and use it in GitHub Desktop.
<?php
namespace modules\temp\console\controllers;
use Craft;
use craft\console\Controller;
use craft\elements\Entry;
use yii\console\ExitCode;
/**
* Reorder Structure controller
*/
class ReorderStructureController extends Controller
{
public $defaultAction = 'index';
/**
* temp/reorder-structure command
*/
public function actionIndex(): int
{
Craft::$app->db->backup();
$entries = Entry::find()
->section('storageLocation')
->all();
foreach ($entries as $entry) {
$this->stdout($entry->title. "\n");
Craft::$app->getStructures()->prependToRoot($entry->structureId, $entry);
}
return ExitCode::OK;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment