Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Update API to reflect changes to CLI interaction #1325

Merged
merged 1 commit into from
Sep 26, 2024
Merged
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: 3 additions & 3 deletions code/Extension/UpgradePolymorphicExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
}
}
}
Expand Down
28 changes: 17 additions & 11 deletions code/Task/UserFormsColumnCleanTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];

Expand All @@ -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();

Expand All @@ -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
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/en/01_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
7 changes: 1 addition & 6 deletions docs/en/03_troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Loading