Skip to content

Commit

Permalink
Merge pull request #3426 in NEXT/platform from next-3806/6.0/auto-upd…
Browse files Browse the repository at this point in the history
…ater to master

* commit '70cafb506f3ad80cb9860a3a0a9910e32ee74939':
  NEXT-3806 - Add blocks
  NEXT-3806 - Auto-Updater
  • Loading branch information
janbuecker committed Jul 4, 2019
2 parents b0907a3 + 70cafb5 commit 569efec
Show file tree
Hide file tree
Showing 57 changed files with 2,710 additions and 5 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/Administration/Resources/administration/src/app/main.js
Expand Up @@ -18,6 +18,7 @@ import SearchTypeService from 'src/app/service/search-type.service';
import ShortcutService from 'src/app/service/shortcut.service';
import LocaleToLanguageService from 'src/app/service/locale-to-language.service';
import addPluginUpdatesListener from 'src/core/service/plugin-updates-listener.service';
import addShopwareUpdatesListener from 'src/core/service/shopware-updates-listener.service';
import 'src/app/decorator';

/** Import global styles */
Expand All @@ -42,6 +43,7 @@ Application
const loginService = LoginService(initContainer.httpClient, serviceContainer.context);

addPluginUpdatesListener(loginService, serviceContainer);
addShopwareUpdatesListener(loginService, serviceContainer);

return loginService;
})
Expand Down
Expand Up @@ -26,6 +26,12 @@
"plugin-updates-listener": {
"updatesAvailableTitle": "Plugin-Updates verfügbar.",
"updatesAvailableMessage": "Für einige Plugins stehen Updates bereit."
},
"shopware-updates-listener": {
"updatesAvailableTitle": "Eine neue Shopware Version {version} ist verfügbar",
"updatesAvailableMessage": "Starte den Auto-Updater um die Installation zu starten",
"cancel": "Schließen",
"updateNow": "Update öffnen"
}
},
"sw-admin-menu": {
Expand Down
Expand Up @@ -26,6 +26,12 @@
"plugin-updates-listener": {
"updatesAvailableTitle": "Plugin-Updates available.",
"updatesAvailableMessage": "For some Plugins are updates available."
},
"shopware-updates-listener": {
"updatesAvailableTitle": "A new Shopware version {version} is available",
"updatesAvailableMessage": "Start the auto-updater to begin the update",
"cancel": "Cancel",
"updateNow": "Open update"
}
},
"sw-admin-menu": {
Expand Down
@@ -0,0 +1,74 @@
import ApiService from '../api.service';

/**
* Gateway for the API end point "update"
* @class
* @extends ApiService
*/
class UpdateService extends ApiService {
constructor(httpClient, loginService, apiEndpoint = 'update') {
super(httpClient, loginService, apiEndpoint);
this.name = 'updateService';
}

checkForUpdates() {
const headers = this.getBasicHeaders();

return this.httpClient
.get(`/_action/${this.getApiBasePath()}/check`, { headers })
.then((response) => {
return ApiService.handleResponse(response);
});
}

checkRequirements() {
const headers = this.getBasicHeaders();

return this.httpClient
.get(`/_action/${this.getApiBasePath()}/check-requirements`, { headers })
.then((response) => {
return ApiService.handleResponse(response);
});
}

pluginCompatibility() {
const headers = this.getBasicHeaders();
const params = this.getBasicParams();

return this.httpClient
.get(`/_action/${this.getApiBasePath()}/plugin-compatibility`, { params, headers })
.then((response) => {
return ApiService.handleResponse(response);
});
}

downloadUpdate(offset) {
const headers = this.getBasicHeaders();

return this.httpClient
.get(`/_action/${this.getApiBasePath()}/download-latest-update?offset=${offset}`, { headers })
.then((response) => {
return ApiService.handleResponse(response);
});
}

unpackUpdate(offset) {
const headers = this.getBasicHeaders();

return this.httpClient
.get(`/_action/${this.getApiBasePath()}/unpack?offset=${offset}`, { headers })
.then((response) => {
return ApiService.handleResponse(response);
});
}

getBasicParams(additionalParams = {}) {
const basicParams = {
language: localStorage.getItem('sw-admin-locale')
};

return Object.assign({}, basicParams, additionalParams);
}
}

export default UpdateService;
@@ -0,0 +1,70 @@
import { Application } from 'src/core/shopware';

/**
* @module core/service/shopware-updates-listener
*/

/**
*
* @memberOf module:core/service/shopware-updates-listener
* @method addShopwareUpdatesListener
* @param loginService
* @param serviceContainer
*/
export default function addShopwareUpdatesListener(loginService, serviceContainer) {
/** @var {String} localStorage token */
let applicationRoot = null;

loginService.addOnLoginListener(() => {
serviceContainer.updateService.checkForUpdates()
.then((response) => {
if (response.version) {
createUpdatesAvailableNotification(response);
}
})
.catch();
});

function createUpdatesAvailableNotification(response) {
const cancelLabel =
getApplicationRootReference().$t('global.notification-center.shopware-updates-listener.cancel');
const updateLabel =
getApplicationRootReference().$t('global.notification-center.shopware-updates-listener.updateNow');

const notification = {
title: getApplicationRootReference().$t(
'global.notification-center.shopware-updates-listener.updatesAvailableTitle', {
version: response.version
}
),
message: getApplicationRootReference().$t(
'global.notification-center.shopware-updates-listener.updatesAvailableMessage', {
version: response.version
}
),
variant: 'info',
growl: true,
system: true,
actions: [{
label: updateLabel,
route: { name: 'sw.settings.shopware.updates.wizard' }
}, {
label: cancelLabel
}],
autoClose: false
};

getApplicationRootReference().$store.dispatch(
'notification/createNotification',
notification
);
}

function getApplicationRootReference() {
if (!applicationRoot) {
applicationRoot = Application.getApplicationRoot();
}

return applicationRoot;
}
}
@@ -0,0 +1,6 @@
import { Component } from 'src/core/shopware';
import template from './sw-settings-index.html.twig';

Component.override('sw-settings-index', {
template
});
@@ -0,0 +1,13 @@
{% block sw_settings_content_card_slot_system %}
{% parent %}

{% block sw_settings_shopware_updates %}
<sw-settings-item id="sw-settings-shopware-updates"
:label="$tc('sw-settings-shopware-updates.general.menuTitle')"
:to="{ name: 'sw.settings.shopware.updates.index' }">
<template slot="icon">
<sw-icon name="default-arrow-360-full"></sw-icon>
</template>
</sw-settings-item>
{% endblock %}
{% endblock %}
@@ -0,0 +1,45 @@
import { Module } from 'src/core/shopware';

import './extension/sw-settings-index';
import './page/sw-settings-shopware-updates-index';
import './page/sw-settings-shopware-updates-wizard';
import './view/sw-settings-shopware-updates-info';
import './view/sw-settings-shopware-updates-requirements';
import './view/sw-settings-shopware-updates-plugins';

import deDE from './snippet/de-DE.json';
import enGB from './snippet/en-GB.json';

Module.register('sw-settings-shopware-updates', {
type: 'core',
name: 'settings-shopware-updates',
title: 'sw-settings-shopware-updates.general.emptyTitle',
description: 'sw-settings-shopware-updates.general.emptyTitle',
version: '1.0.0',
targetVersion: '1.0.0',
color: '#9AA8B5',
icon: 'default-action-settings',
favicon: 'icon-module-settings.png',

snippets: {
'de-DE': deDE,
'en-GB': enGB
},

routes: {
index: {
component: 'sw-settings-shopware-updates-index',
path: 'index',
meta: {
parentPath: 'sw.settings.index'
}
},
wizard: {
component: 'sw-settings-shopware-updates-wizard',
path: 'wizard',
meta: {
parentPath: 'sw.settings.index'
}
}
}
});
@@ -0,0 +1,80 @@
import { Component, Mixin, Application } from 'src/core/shopware';
import template from './sw-settings-shopware-updates-index.html.twig';
import './sw-settings-shopware-updates-index.scss';

Component.register('sw-settings-shopware-updates-index', {
template,

inject: ['updateService'],
mixins: [
Mixin.getByName('notification')
],
data() {
return {
isLoading: false,
isSaveSuccessful: false,
isSearchingForUpdates: false,
updateModalShown: false,
updateInfo: null
};
},

metaInfo() {
return {
title: this.$createTitle()
};
},

methods: {
searchForUpdates() {
this.isSearchingForUpdates = true;
this.updateService.checkForUpdates().then(response => {
this.isSearchingForUpdates = false;

if (response.version) {
this.updateInfo = response;
this.updateModalShown = true;
} else {
this.createNotificationSuccess({
title: this.$t('sw-settings-shopware-updates.notifications.title'),
message: this.$t('sw-settings-shopware-updates.notifications.alreadyUpToDate')
});
}
});
},

openUpdateWizard() {
this.updateModalShown = false;

this.$nextTick(() => {
this.$router.push({ name: 'sw.settings.shopware.updates.wizard' });
});
},

saveFinish() {
this.isSaveSuccessful = false;
},

onSave() {
this.isSaveSuccessful = false;
this.isLoading = true;

this.$refs.systemConfig.saveAll().then(() => {
this.isLoading = false;
this.isSaveSuccessful = true;
}).catch((err) => {
this.isLoading = false;
this.createNotificationError({
title: this.$tc('sw-settings-store.general.titleSaveError'),
message: err
});
});
}
},

computed: {
shopwareVersion() {
return Application.getContainer('init').contextService.config.version;
}
}
});

0 comments on commit 569efec

Please sign in to comment.