Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Update API to reflect changes to CLI interaction
Browse files Browse the repository at this point in the history
GuySartorelli committed Sep 25, 2024

Verified

This commit was signed with the committer’s verified signature.
GuySartorelli Guy Sartorelli
1 parent 5cbe51b commit a9481b7
Showing 5 changed files with 23 additions and 22 deletions.
6 changes: 3 additions & 3 deletions code/Extension/UpgradePolymorphicExtension.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
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.
*
* Various `Parent` relationships in silverstripe/userforms for SilverStripe 3 were mapped directly to UserDefinedForm
@@ -83,9 +83,9 @@ protected function onRequireDefaultRecords()
$entry->write();
$updated++;
} 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
// logic will work the next time dev/build is run.
// logic will work the next time the db is built.
}
}
}
28 changes: 17 additions & 11 deletions code/Task/UserFormsColumnCleanTask.php
Original file line number Diff line number Diff line change
@@ -2,10 +2,13 @@

namespace SilverStripe\UserForms\Task;

use SilverStripe\Dev\MigrationTask;
use SilverStripe\Dev\BuildTask;
use SilverStripe\PolyExecution\PolyOutput;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\UserForms\Model\EditableFormField;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;

/**
* UserForms Column Clean Task
@@ -15,11 +18,13 @@
* @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];

@@ -28,7 +33,7 @@ class UserFormsColumnCleanTask extends MigrationTask
/**
* Publish the existing forms.
*/
public function run($request)
protected function execute(InputInterface $input, PolyOutput $output): int
{
$schema = DataObject::getSchema();

@@ -40,28 +45,29 @@ public function run($request)
$query = "SHOW TABLES LIKE 'Backup_$db'";
$tableExists = DB::query($query)->value();
if ($tableExists != null) {
echo "Tasks run already on $db exiting";
return;
$output->writeln("Tasks run already on $db exiting");
return Command::SUCCESS;
}
$backedUp = 0;
foreach ($liveColumns as $index => $column) {
if ($backedUp == 0) {
echo "Backing up $db <br />";
echo "Creating Backup_$db <br />";
$output->writeln("Backing up $db <br />");
$output->writeln("Creating Backup_$db <br />");
// backup table
$query = "CREATE TABLE Backup_$db LIKE $db";
DB::query($query);
echo "Populating Backup_$db <br />";
$output->writeln("Populating Backup_$db <br />");
$query = "INSERT Backup_$db SELECT * FROM $db";
DB::query($query);
$backedUp = 1;
}
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";
DB::query($query);
}
}
}
return Command::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion code/UserForm.php
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ trait UserForm
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
* @var bool
2 changes: 1 addition & 1 deletion docs/en/01_installation.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ composer require silverstripe/userforms

## 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.

7 changes: 1 addition & 6 deletions docs/en/03_troubleshooting.md
Original file line number Diff line number Diff line change
@@ -6,11 +6,6 @@ title: Troubleshooting

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

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
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

0 comments on commit a9481b7

Please sign in to comment.