Hi
I am trying to catch and listen to Upgrade event for Confluence but seems like it is not working. I have already implemented listener for PluginEnableEvent and it is working but unfortunately it does not work for PluginUpgradedEvent. Here is the sample code
public class UpgradeEventListener implements InitializingBean, DisposableBean{
private static final Logger log =
LoggerFactory.getLogger(CacheAnalyticsListener.class);
private final EventPublisher eventPublisher;
public UpgradeEventListener(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
this.eventPublisher.register(this);
}
@PluginEventListener
public void onPluginUpgrade(PluginUpgradedEvent event) {
Plugin thisPlugin = event.getPlugin();
//do something here
}
@Override
public void destroy() throws Exception {
log.info("destroy called");
eventPublisher.unregister(this);
}
@Override
public void afterPropertiesSet() throws Exception {
}
}
Please help.
hey @prakhar.srivastav maybe i found something for you.
i looked at the plugin-manager source code, because i thought, it should be possible to find an answer there.
available here: Bitbucket
in line 1198 there is an IF that decides if PluginUpgradedEvent or PluginInstalledEvent is broadcast.
Looking at the lines above, 1142, there is a comparison i did not look into in more detail:
plugin.compareTo(existingPlugin) >= 0
Maybe this is a good start to further investigate, why the event is not broadcast.
You could also try listening for PluginInstalledEvent, if this is acceptable for your use case?
You also need to register your listener as a component, we are achieving that the following annotation from atlassian spring scanner :
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
@Component
public class ContentStatusUpdateListener {
private final EventPublisher eventPublisher;
@Autowired
public ContentStatusUpdateListener(
final @ComponentImport EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
@PostConstruct
public void register() {
eventPublisher.register(this);
}
@PreDestroy
public void unregister() {
eventPublisher.unregister(this);
}
@EventListener
public void onPageUpdate(final PageUpdateEvent event) {
final ContentEntityObject updated = event.getContent();
if (updated.getContentStatusObject().equals(ContentStatus.TRASHED)) {
// TODO
}
}
}