public function upgradePlugin($pluginSlug, $pluginPath, Errors &$errors)
    {
        $log = "";

        $plugin = $this->PluginService->getBySlug($pluginSlug);
        $existingPriority = $plugin->Priority;

        if (empty($plugin) || !$plugin->isInstalled()) {
            $log .= "Plugin is not installed.";
            return array($log, 'fail');
        }

        $log .= "Upgrading plugin [$pluginSlug]...\n";

        $xml = $this->loadXML($plugin->Path);
        $originalVersion = $plugin->Version;

        $plugin = $this->SystemXMLConverter->xmlToPlugin($plugin, $xml);
        $plugin->Priority = $existingPriority;
        $plugin->ModifiedDate = $this->DateFactory->newStorageDate(filemtime($pluginPath.'/plugin.xml'));
        $plugin->Md5 = md5_file($pluginPath.'/plugin.xml');

        $this->PluginService->edit($plugin);

        $plugin = $this->PluginService->getBySlug($pluginSlug);


        $this->processAspects($plugin, $log);

        foreach($this->ElementService->findAll()->getResults() as $element)
            $this->NodeService->createDBSchema($element);

        $this->processPluginXML($plugin, $errors, $log, $xml);


        $errors->throwOnError();

        $this->processUpgradeScript($plugin, $log, $originalVersion);


        $this->ApplicationContext->clearContextFiles();

        return array($log, strpos($log, 'WARNING')=== FALSE?'success':'warn');
    }