Skip to content

Commit c35b664

Browse files
committed
Add core update-db #22
1 parent f5901bd commit c35b664

3 files changed

Lines changed: 59 additions & 9 deletions

File tree

src/org/netbeans/modules/php/wordpress/WordPressCoreUpgradeChecker.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@
4646
import java.io.IOException;
4747
import java.net.MalformedURLException;
4848
import java.util.Collections;
49+
import java.util.concurrent.ExecutionException;
50+
import java.util.concurrent.Future;
4951
import java.util.logging.Level;
5052
import java.util.logging.Logger;
5153
import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
5254
import org.netbeans.modules.php.api.phpmodule.PhpModule;
5355
import org.netbeans.modules.php.api.util.StringUtils;
54-
import org.netbeans.modules.php.wordpress.wpapis.WordPressVersionCheckApi;
5556
import org.netbeans.modules.php.wordpress.commands.WordPressCli;
5657
import org.netbeans.modules.php.wordpress.ui.options.WordPressOptions;
58+
import org.netbeans.modules.php.wordpress.wpapis.WordPressVersionCheckApi;
5759
import org.openide.DialogDisplayer;
5860
import org.openide.NotifyDescriptor;
5961
import org.openide.awt.NotificationDisplayer;
@@ -161,7 +163,7 @@ public CoreUpdateActionListener(PhpModule phpModule) {
161163
this.phpModule = phpModule;
162164
}
163165

164-
@NbBundle.Messages("CoreUpdateActionListener.comfirmation=Do you want to update? (run wp core update)")
166+
@NbBundle.Messages("CoreUpdateActionListener.comfirmation=Do you want to update? (run wp core update, update-db)")
165167
@Override
166168
public void actionPerformed(ActionEvent e) {
167169
if (StringUtils.isEmpty(WordPressOptions.getInstance().getWpCliPath())) {
@@ -176,12 +178,31 @@ public void actionPerformed(ActionEvent e) {
176178
if (DialogDisplayer.getDefault().notify(comfirmation) != NotifyDescriptor.OK_OPTION) {
177179
return;
178180
}
179-
try {
180-
WordPressCli wpCli = WordPressCli.getDefault(true);
181-
wpCli.coreUpdate(phpModule, Collections.<String>emptyList());
182-
} catch (InvalidPhpExecutableException ex) {
183-
Exceptions.printStackTrace(ex);
184-
}
181+
182+
new Thread(new Runnable() {
183+
184+
@Override
185+
public void run() {
186+
try {
187+
// core update, update-db
188+
WordPressCli wpCli = WordPressCli.getDefault(true);
189+
Future<Integer> result = wpCli.coreUpdate(phpModule, Collections.<String>emptyList());
190+
if (result != null) {
191+
result.get();
192+
}
193+
result = wpCli.coreUpdateDb(phpModule);
194+
if (result != null) {
195+
result.get();
196+
}
197+
} catch (InvalidPhpExecutableException ex) {
198+
Exceptions.printStackTrace(ex);
199+
} catch (InterruptedException ex) {
200+
Exceptions.printStackTrace(ex);
201+
} catch (ExecutionException ex) {
202+
Exceptions.printStackTrace(ex);
203+
}
204+
}
205+
}).start();
185206
}
186207
}
187208

src/org/netbeans/modules/php/wordpress/WordPressVersion.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@
4141
*/
4242
package org.netbeans.modules.php.wordpress;
4343

44+
import java.util.Collection;
4445
import java.util.HashMap;
4546
import java.util.Map;
4647
import org.netbeans.modules.php.api.phpmodule.PhpModule;
48+
import org.netbeans.modules.php.wordpress.ui.status.DebugStatusLineElement;
4749
import org.netbeans.modules.php.wordpress.util.WPFileUtils;
4850
import org.netbeans.modules.php.wordpress.util.WPUtils;
51+
import org.openide.awt.StatusLineElementProvider;
4952
import org.openide.filesystems.FileChangeAdapter;
5053
import org.openide.filesystems.FileEvent;
5154
import org.openide.filesystems.FileObject;
55+
import org.openide.util.Lookup;
5256

5357
/**
5458
*
@@ -96,6 +100,16 @@ private WordPressVersion(String versionNumber, FileObject versionFile) {
96100
public void fileChanged(FileEvent fe) {
97101
FileObject versionFile = fe.getFile();
98102
initVersion(WPUtils.getVersion(versionFile));
103+
104+
// reset status bar
105+
Collection<? extends StatusLineElementProvider> elements = Lookup.getDefault().lookupAll(StatusLineElementProvider.class);
106+
for (StatusLineElementProvider element : elements) {
107+
if (element instanceof DebugStatusLineElement) {
108+
DebugStatusLineElement debugElement = (DebugStatusLineElement) element;
109+
debugElement.setPhpModule(null);
110+
break;
111+
}
112+
}
99113
}
100114
});
101115
}

src/org/netbeans/modules/php/wordpress/commands/WordPressCli.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public final class WordPressCli {
8484
public static String LONG_NAME = "wp-cli.phar"; // NOI18N
8585

8686
private final String wpCliPath;
87+
private boolean noReset = false;
8788
private static final Logger LOGGER = Logger.getLogger(WordPressCli.class.getName());
8889

8990
// commands
@@ -93,6 +94,7 @@ public final class WordPressCli {
9394
private static final String CORE_COMMAND = "core"; // NOI18N
9495
private static final String DOWNLOAD_COMMAND = "download"; // NOI18N
9596
private static final String UPDATE_COMMAND = "update"; // NOI18N
97+
private static final String UPDATE_DB_COMMAND = "update-db"; // NOI18N
9698

9799
// params
98100
private static final String HELP_PARAM = "--help"; // NOI18N
@@ -161,6 +163,19 @@ public Future<Integer> coreUpdate(PhpModule phpModule, List<String> options) {
161163
return runCommand(phpModule, allCommands);
162164
}
163165

166+
/**
167+
* Core update-db.
168+
*
169+
* @param phpModule
170+
* @return
171+
*/
172+
public Future<Integer> coreUpdateDb(PhpModule phpModule) {
173+
ArrayList<String> allCommands = new ArrayList<String>(2);
174+
allCommands.add(CORE_COMMAND);
175+
allCommands.add(UPDATE_DB_COMMAND);
176+
return runCommand(phpModule, allCommands);
177+
}
178+
164179
/**
165180
* Get wp-cli version.
166181
*
@@ -362,7 +377,7 @@ public Future<Integer> runCommand(PhpModule phpModule, List<String> parameters)
362377
if (executable == null) {
363378
return null;
364379
}
365-
return executable.displayName(getDisplayName(phpModule, parameters.get(0)))
380+
return executable.displayName(getDisplayName(phpModule, StringUtils.implode(parameters, " "))) // NOI18N
366381
.additionalParameters(getAllParameters(parameters))
367382
.run(getExecutionDescriptor(null));
368383
}

0 commit comments

Comments
 (0)