Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrelopez committed Apr 3, 2018
2 parents 6dcc410 + c86653b commit 503bbf0
Show file tree
Hide file tree
Showing 26 changed files with 292 additions and 187 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Enupal Backup Changelog

## 1.0.9 - 2018.04.03
### Added
- Added Plugin name override setting

### Improved
- Improved code inspections

## 1.0.8 - 2018.02.22
### Added
- Added PSR2 support
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright © Enupal
Copyright © Enupal LLC

Permission is hereby granted to any person obtaining a copy of this software
(the “Software”) to use, copy, modify, merge, publish and/or distribute copies
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "enupal/backup",
"description": "Fully integrated Backup solution for Craft CMS",
"type": "craft-plugin",
"version": "1.0.8",
"version": "1.0.9",
"keywords": [
"craft",
"cms",
Expand Down
13 changes: 11 additions & 2 deletions src/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
namespace enupal\backup;

use Craft;
use craft\base\Plugin;
use craft\events\RegisterUrlRulesEvent;
use craft\web\UrlManager;
use yii\base\Event;
use craft\events\DefineComponentsEvent;
use craft\web\twig\variables\CraftVariable;
use craft\services\SystemMessages;
use craft\events\RegisterEmailMessagesEvent;

use enupal\backup\variables\BackupVariable;
use enupal\backup\models\Settings;

class Backup extends \craft\base\Plugin
class Backup extends Plugin
{
/**
* Enable use of Backup::$app-> in place of Craft::$app->
Expand All @@ -38,6 +38,12 @@ public function init()
parent::init();
self::$app = $this->get('app');

$settings = Backup::$app->settings->getDbSettings();

if (isset($settings['pluginNameOverride']) && $settings['pluginNameOverride']){
$this->name = $settings['pluginNameOverride'];
}

Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function(RegisterUrlRulesEvent $event) {
$event->rules = array_merge($event->rules, $this->getCpUrlRules());
}
Expand Down Expand Up @@ -82,6 +88,7 @@ protected function afterInstall()
* Performs actions before the plugin is Uninstalled.
*
* @return bool Whether the plugin should be Uninstalled
* @throws \Throwable
*/
protected function beforeUninstall(): bool
{
Expand Down Expand Up @@ -120,6 +127,8 @@ public function getCpNavItem()
* Settings HTML
*
* @return string
* @throws \Twig_Error_Loader
* @throws \yii\base\Exception
*/
protected function settingsHtml()
{
Expand Down
4 changes: 3 additions & 1 deletion src/contracts/BackupConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public function addBackup(BackupType $backup)
/**
* Returns the backup config
*
* @return []
* @param bool $asJson
*
* @return array|string []
*/
public function getConfig($asJson = false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/BackupType.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class BackupType
/**
* Returns the backup array
*
* @return []
* @return []
*/
abstract public function getBackup();
}
19 changes: 13 additions & 6 deletions src/controllers/BackupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@

class BackupsController extends BaseController
{
/*
/**
* Download backup
*/
*
* @return \yii\web\Response|static
* @throws NotFoundHttpException
* @throws \Exception
* @throws \yii\web\BadRequestHttpException
*/
public function actionDownload()
{
$this->requirePostRequest();
Expand All @@ -42,16 +47,16 @@ public function actionDownload()

if (is_file($zipPath)) {
try {
FileHelper::removeFile($zipPath);
} catch (ErrorException $e) {
FileHelper::unlink($zipPath);
} catch (\Exception $e) {
Backup::error("Unable to delete the file \"{$zipPath}\": ".$e->getMessage());
}
}

$zip = new ZipArchive();

if ($zip->open($zipPath, ZipArchive::CREATE) !== true) {
throw new Exception('Cannot create zip at '.$zipPath);
throw new \Exception('Cannot create zip at '.$zipPath);
}

if ($backup->getDatabaseFile()) {
Expand Down Expand Up @@ -129,6 +134,7 @@ public function actionRun()
*
* @param int|null $backupId The backup's ID
*
* @return \yii\web\Response
* @throws HttpException
* @throws Exception
*/
Expand Down Expand Up @@ -177,7 +183,8 @@ public function actionViewBackup(int $backupId = null)
/**
* Delete a backup.
*
* @return void
* @return \yii\web\Response
* @throws \yii\web\BadRequestHttpException
*/
public function actionDeleteBackup()
{
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class SettingsController extends BaseController
/**
* Save Plugin Settings
*
* @return void
* @return null|\yii\web\Response
* @throws \yii\web\BadRequestHttpException
*/
public function actionSaveSettings()
{
Expand Down
6 changes: 2 additions & 4 deletions src/controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class WebhookController extends BaseController
/**
* Webhook to listen when a backup process finish up
*
* @param $backupId
*
* @return \yii\web\Response
*/
public function actionFinished()
{
Expand Down Expand Up @@ -56,8 +55,7 @@ public function actionFinished()
/**
* Webhook to listen when a cronjob call EnupalBackup process
*
* @param $backupId
*
* @return \yii\web\Response
*/
public function actionSchedule()
{
Expand Down
7 changes: 3 additions & 4 deletions src/elements/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public function getCpEditUrl()
public function __toString()
{
try {
// @todo - For some reason the Title returns null possible Craft3 bug
return $this->backupId;
} catch (\Exception $e) {
ErrorHandler::convertExceptionToError($e);
Expand Down Expand Up @@ -284,7 +283,7 @@ protected function tableAttributeHtml(string $attribute): string
}
case 'dateCreated':
{
return $this->dateCreated->format("Y-m-d H:i");;
return $this->dateCreated->format("Y-m-d H:i");
}
}

Expand Down Expand Up @@ -365,7 +364,7 @@ public function getTotalSize()

/**
* @inheritdoc
* @throws Exception if reasons
* @throws \Exception if reasons
*/
public function afterSave(bool $isNew)
{
Expand All @@ -374,7 +373,7 @@ public function afterSave(bool $isNew)
$record = BackupRecord::findOne($this->id);

if (!$record) {
throw new Exception('Invalid Backup ID: '.$this->id);
throw new \Exception('Invalid Backup ID: '.$this->id);
}
} else {
$record = new BackupRecord();
Expand Down
1 change: 1 addition & 0 deletions src/jobs/CreateBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use enupal\backup\Backup;
use craft\queue\BaseJob;
use enupal\backup\elements\Backup as BackupElement;

use enupal\backup\enums\BackupStatus;

Expand Down
4 changes: 3 additions & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace enupal\backup\models;

use craft\base\Model;
use enupal\backup\validators\BackupFilesValidator;
use enupal\backup\validators\AssetSourceValidator;
use enupal\backup\validators\DropboxValidator;
Expand All @@ -17,7 +18,7 @@
use enupal\backup\validators\NotificationValidator;
use enupal\backup\validators\RecipientsValidator;

class Settings extends \craft\base\Model
class Settings extends Model
{
// General
public $pluginNameOverride = '';
Expand Down Expand Up @@ -92,6 +93,7 @@ public function rules()
{
return [
['backupsAmount', 'integer', 'min' => 1, 'on' => 'general'],
['backupsAmount', 'required', 'on' => 'general'],
[
['enableDatabase', 'enableTemplates', 'enableLocalVolumes', 'enableLogs'],
BackupFilesValidator::class, 'on' => 'backupFiles'
Expand Down
Loading

0 comments on commit 503bbf0

Please sign in to comment.