33
33
34
34
use ArtificialOwl \MySmallPhpTools \Traits \Nextcloud \nc23 \TNC23Deserialize ;
35
35
use OC \Core \Command \Base ;
36
+ use OCA \Backup \Exceptions \ExternalAppdataException ;
36
37
use OCA \Backup \Exceptions \ExternalFolderNotFoundException ;
37
38
use OCA \Backup \Service \ConfigService ;
38
39
use OCA \Backup \Service \ExternalFolderService ;
39
40
use OCA \Backup \Service \PointService ;
40
41
use OCA \Files_External \Lib \InsufficientDataForMeaningfulAnswerException ;
41
42
use OCP \Files \StorageNotAvailableException ;
42
43
use Symfony \Component \Console \Input \InputInterface ;
44
+ use Symfony \Component \Console \Input \InputOption ;
43
45
use Symfony \Component \Console \Output \OutputInterface ;
44
46
use Symfony \Component \Console \Question \ChoiceQuestion ;
45
47
use Symfony \Component \Console \Question \ConfirmationQuestion ;
@@ -89,7 +91,8 @@ public function __construct(
89
91
*/
90
92
protected function configure () {
91
93
$ this ->setName ('backup:external:appdata ' )
92
- ->setDescription ('Add external filesystem to store the app \'s data ' );
94
+ ->setDescription ('Add external filesystem to store the app \'s data ' )
95
+ ->addOption ('unset ' , '' , InputOption::VALUE_NONE , 'Unset the current external appdata ' );
93
96
}
94
97
95
98
@@ -103,15 +106,56 @@ protected function configure() {
103
106
* @throws ExternalFolderNotFoundException
104
107
*/
105
108
protected function execute (InputInterface $ input , OutputInterface $ output ): int {
106
- $ output ->writeln (
107
- 'This configuration tool will help you set the <info>Appdata</info> folder of the Backup App on an <info>external storage</info> '
108
- );
109
- $ output ->writeln ('... ' );
109
+ $ unset = $ input ->getOption ('unset ' );
110
+
111
+ try {
112
+ $ external = $ this ->pointService ->getExternalAppData ();
113
+ $ output ->writeln ('Your <info>appdata</info> is currently on an external storage: ' );
114
+ $ output ->writeln ('Storage Id: <info> ' . $ external ->getStorageId () . '</info> ' );
115
+ $ output ->writeln ('Storage: <info> ' . $ external ->getStorage () . '</info> ' );
116
+ $ output ->writeln ('Root: <info> ' . $ external ->getRoot () . '</info> ' );
117
+ $ output ->writeln ('' );
118
+
119
+ if (!$ unset ) {
120
+ return 0 ;
121
+ }
122
+ } catch (ExternalAppdataException $ e ) {
123
+ $ unset = false ;
124
+ }
125
+
126
+ if (!$ unset ) {
127
+ $ output ->writeln (
128
+ 'This configuration tool will help you set the <info>Appdata</info> folder '
129
+ . ' of the Backup App on an <info>external storage</info> '
130
+ );
131
+ }
132
+
133
+ $ output ->writeln ('' );
110
134
$ output ->writeln ('' );
111
135
$ output ->writeln ('<error>All previous Restoring Point will be lost during this process</error> ' );
112
136
$ output ->writeln ('' );
113
137
$ output ->writeln ('' );
138
+
139
+ if ($ unset ) {
140
+ $ question = new ConfirmationQuestion (
141
+ '<comment>Do you really want to not use this External Folder appdata anymore ?</comment> (y/N) ' ,
142
+ false ,
143
+ '/^(y|Y)/i '
144
+ );
145
+
146
+ $ helper = $ this ->getHelper ('question ' );
147
+ if (!$ helper ->ask ($ input , $ output , $ question )) {
148
+ $ output ->writeln ('Operation cancelled ' );
149
+ }
150
+
151
+ $ this ->pointService ->setExternalAppData (0 );
152
+
153
+ return 0 ;
154
+ }
155
+
156
+
114
157
$ storageId = $ this ->selectStorage ($ input , $ output );
158
+
115
159
$ output ->writeln ('' );
116
160
if ($ storageId === 0 ) {
117
161
$ output ->writeln ('Operation cancelled ' );
0 commit comments