-
Notifications
You must be signed in to change notification settings - Fork 0
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
Craft 4.0 support #1
Comments
Sure thing! I'll take a look at it this week.
…On Fri, May 12, 2023 at 7:37 AM NeleDeBruycker ***@***.***> wrote:
Hi,
Would it be possible to also support Craft 4.0?
We want to upgrade a project that is using this plugin to Craft 4.0 but we
get an error.
Thanks in advance,
Nele
—
Reply to this email directly, view it on GitHub
<#1>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA6BIRQ4CYVRKFEDAJKK5TXFYVJVANCNFSM6AAAAAAX7PA4HI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
*Sam Hernandez, Front End Architect - Precocity*
Office: (972) 378-1030 - Direct: (925) 708-6454
***@***.*** ***@***.***>* -
www.precocityllc.com
|
Hi @samhernandez do you have any updates on this? |
1 similar comment
Hi @samhernandez do you have any updates on this? |
Hi @samhernandez any chance you can have a look at this? |
I modified the code of this repo and made my own module for it inside my own project, might be of use for you :). This is tested on Craft 4.8.1 using Laravel Valet Note: This only supports MYSQL but could easily be updated to use PSQL File location: modules/backupmodule/BackupModule.php <?php
namespace modules\backupmodule;
use Craft;
use craft\helpers\App;
use yii\base\ErrorException;
use yii\base\Exception;
use yii\base\Module as BaseModule;
use yii\base\NotSupportedException;
/**
* BackupModule module
*
* @method static BackupModule getInstance()
*/
class BackupModule extends BaseModule
{
/**
* Initializes the module.
*
* This method is called after the module is created and initialized with property values
* given in configuration. The default implementation will initialize [[controllerNamespace]]
* if it is not set.
*
* If you override this method, please make sure you call the parent implementation.
* @throws ErrorException
* @throws NotSupportedException
* @throws Exception
*/
public function init(): void
{
Craft::setAlias('@modules/backupmodule', __DIR__);
// Set the controllerNamespace based on whether this is a console or web request
if (Craft::$app->request->isConsoleRequest) {
$this->controllerNamespace = 'modules\\backupmodule\\console\\controllers';
} else {
$this->controllerNamespace = 'modules\\backupmodule\\controllers';
}
if (Craft::$app->getRequest()->isCpRequest) {
try {
$this->patchMysqlCommands();
} catch (ErrorException $e) {
throw new ErrorException($e);
} catch (NotSupportedException $e) {
throw new NotSupportedException($e);
} catch (Exception $e) {
throw new Exception($e);
}
}
}
/**
* Patches the backup and restore commands with the given path to mysql and mysqldump.
* Useful for when the "mysql" or "mysqldump" commands are not found (e.g. when ran on a Valet environment)
* @throws ErrorException
* @throws NotSupportedException
* @throws Exception
*/
protected function patchMysqlCommands(): void
{
$mysqlDumpPath = App::env('MYSQLDUMP_PATH');
$mysqlPath = App::env('MYSQL_PATH');
if (Craft::$app->db->getDriverName() !== 'mysql') {
return;
}
if ($mysqlDumpPath) {
Craft::$app->config->general->backupCommand = str_replace(
'mysqldump',
$mysqlDumpPath,
Craft::$app->db->getSchema()->getDefaultBackupCommand()
);
}
if ($mysqlPath) {
Craft::$app->config->general->restoreCommand = str_replace(
'mysql',
$mysqlPath,
Craft::$app->db->getSchema()->getDefaultRestoreCommand()
);
}
}
} In your composer.json file update your autoload psr-4 entry to include the module: "autoload": {
"psr-4": {
"modules\\backupmodule\\": "modules/backupmodule/"
}
}, Also have to add your module in app.php: <?php
use craft\helpers\App;
use modules\backupmodule\BackupModule;
return [
'id' => App::env('APP_ID') ?: 'CraftCMS',
'modules' => [
'backup-module' => [
'class' => BackupModule::class,
]
],
'bootstrap' => ['backup-module'],
]; Finally run the following command to make sure composer changes are picked up:
Don't forget to add these to your .env file MYSQL_PATH="/usr/local/opt/[email protected]/bin/mysql"
MYSQLDUMP_PATH="/usr/local/opt/[email protected]/bin/mysqldump" Ofcourse these paths could be different for you. You could run |
Hi,
Would it be possible to also support Craft 4.0?
We want to upgrade a project that is using this plugin to Craft 4.0 but we get an error.
Thanks in advance,
Nele
The text was updated successfully, but these errors were encountered: