API Update API to reflect changes to CLI interaction (#1325)

This commit is contained in:
Guy Sartorelli 2024-09-26 17:18:38 +12:00 committed by GitHub
parent b3337c7574
commit f50db11539
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 22 deletions

View File

@ -15,7 +15,7 @@ use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\UserForms\UserForm; use SilverStripe\UserForms\UserForm;
/** /**
* This extension provides a hook that runs during a dev/build which will check for existing data in various * This extension provides a hook that runs when building the db which will check for existing data in various
* polymorphic relationship fields for userforms models, and ensure that the data is correct. * polymorphic relationship fields for userforms models, and ensure that the data is correct.
* *
* Various `Parent` relationships in silverstripe/userforms for SilverStripe 3 were mapped directly to UserDefinedForm * Various `Parent` relationships in silverstripe/userforms for SilverStripe 3 were mapped directly to UserDefinedForm
@ -83,9 +83,9 @@ class UpgradePolymorphicExtension extends Extension
$entry->write(); $entry->write();
$updated++; $updated++;
} catch (ValidationException $ex) { } catch (ValidationException $ex) {
// no-op, allow the rest of dev/build to continue. There may be an error indicating that the // no-op, allow the rest of the db build to continue. There may be an error indicating that the
// object's class doesn't exist, which can be fixed by {@link DatabaseAdmin::doBuild} and this // object's class doesn't exist, which can be fixed by {@link DatabaseAdmin::doBuild} and this
// logic will work the next time dev/build is run. // logic will work the next time the db is built.
} }
} }
} }

View File

@ -2,10 +2,13 @@
namespace SilverStripe\UserForms\Task; namespace SilverStripe\UserForms\Task;
use SilverStripe\Dev\MigrationTask; use SilverStripe\Dev\BuildTask;
use SilverStripe\PolyExecution\PolyOutput;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\UserForms\Model\EditableFormField; use SilverStripe\UserForms\Model\EditableFormField;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
/** /**
* UserForms Column Clean Task * UserForms Column Clean Task
@ -15,11 +18,13 @@ use SilverStripe\UserForms\Model\EditableFormField;
* @package userforms * @package userforms
*/ */
class UserFormsColumnCleanTask extends MigrationTask class UserFormsColumnCleanTask extends BuildTask
{ {
protected $title = 'UserForms EditableFormField Column Clean task'; protected static string $commandName = 'userforms-column-clean';
protected $description = 'Removes unused columns from EditableFormField for MySQL databases;'; protected string $title = 'UserForms EditableFormField Column Clean task';
protected static string $description = 'Removes unused columns from EditableFormField for MySQL databases;';
protected $tables = [EditableFormField::class]; protected $tables = [EditableFormField::class];
@ -28,7 +33,7 @@ class UserFormsColumnCleanTask extends MigrationTask
/** /**
* Publish the existing forms. * Publish the existing forms.
*/ */
public function run($request) protected function execute(InputInterface $input, PolyOutput $output): int
{ {
$schema = DataObject::getSchema(); $schema = DataObject::getSchema();
@ -40,28 +45,29 @@ class UserFormsColumnCleanTask extends MigrationTask
$query = "SHOW TABLES LIKE 'Backup_$db'"; $query = "SHOW TABLES LIKE 'Backup_$db'";
$tableExists = DB::query($query)->value(); $tableExists = DB::query($query)->value();
if ($tableExists != null) { if ($tableExists != null) {
echo "Tasks run already on $db exiting"; $output->writeln("Tasks run already on $db exiting");
return; return Command::SUCCESS;
} }
$backedUp = 0; $backedUp = 0;
foreach ($liveColumns as $index => $column) { foreach ($liveColumns as $index => $column) {
if ($backedUp == 0) { if ($backedUp == 0) {
echo "Backing up $db <br />"; $output->writeln("Backing up $db <br />");
echo "Creating Backup_$db <br />"; $output->writeln("Creating Backup_$db <br />");
// backup table // backup table
$query = "CREATE TABLE Backup_$db LIKE $db"; $query = "CREATE TABLE Backup_$db LIKE $db";
DB::query($query); DB::query($query);
echo "Populating Backup_$db <br />"; $output->writeln("Populating Backup_$db <br />");
$query = "INSERT Backup_$db SELECT * FROM $db"; $query = "INSERT Backup_$db SELECT * FROM $db";
DB::query($query); DB::query($query);
$backedUp = 1; $backedUp = 1;
} }
if (!isset($columns[$column]) && !in_array($column, $this->keepColumns ?? [])) { if (!isset($columns[$column]) && !in_array($column, $this->keepColumns ?? [])) {
echo "Dropping $column from $db <br />"; $output->writeln("Dropping $column from $db <br />");
$query = "ALTER TABLE $db DROP COLUMN $column"; $query = "ALTER TABLE $db DROP COLUMN $column";
DB::query($query); DB::query($query);
} }
} }
} }
return Command::SUCCESS;
} }
} }

View File

@ -65,7 +65,7 @@ trait UserForm
private static $email_template_directory = 'silverstripe/userforms:templates/email/'; private static $email_template_directory = 'silverstripe/userforms:templates/email/';
/** /**
* Should this module automatically upgrade on dev/build? * Should this module automatically upgrade on db build?
* *
* @config * @config
* @var bool * @var bool

View File

@ -12,7 +12,7 @@ composer require silverstripe/userforms
## Configuration ## Configuration
After installation, make sure you rebuild your database through `dev/build`. After installation, make sure you rebuild your database through `sake db:build --flush`.
You should see a new page type in the CMS called "User Defined Form". This has a new "Form" tab which has your form builder. You should see a new page type in the CMS called "User Defined Form". This has a new "Form" tab which has your form builder.

View File

@ -6,11 +6,6 @@ title: Troubleshooting
Check the below if you have any issues during installation or use Check the below if you have any issues during installation or use
## Installation issues
After installation make sure you have done a `dev/build` you may also need to flush the admin view by appending
`?flush=1` to the URL, e.g. `https://example.com/admin?flush=1`
## Checkbox or radio group custom messages not showing ## Checkbox or radio group custom messages not showing
If your project has a custom template for `UserFormsCheckboxSetField.ss` or `UserFormsOptionSetField.ss`, then you will need to ensure they include `$Top.getValidationAttributesHTML().RAW`. See If your project has a custom template for `UserFormsCheckboxSetField.ss` or `UserFormsOptionSetField.ss`, then you will need to ensure they include `$Top.getValidationAttributesHTML().RAW`. See
@ -28,7 +23,7 @@ Currently it only supports MySQL and when it is run it queries the EditableFormF
it then grabs the columns for the live database. It will create a backup of the table and then remove any columns that it then grabs the columns for the live database. It will create a backup of the table and then remove any columns that
are surplus. are surplus.
To run the task, log in as an administrator and go to `https://example.com/dev/tasks/UserFormsColumnCleanTask` in your browser, or run `sake dev/tasks/UserFormsColumnCleanTask` from the command line. To run the task, log in as an administrator and go to `https://example.com/dev/tasks/userforms-column-clean` in your browser, or run `sake tasks:userforms-column-clean` from the command line.
## My CSV export times out or runs out of memory ## My CSV export times out or runs out of memory