public function is_remote_plugin_installable($component, $version, &$reason=null) {
        global $CFG;

        // Make sure the feature is not disabled.
        if (!empty($CFG->disableupdateautodeploy)) {
            $reason = 'disabled';
            return false;
        }

        // Make sure the version is available.
        if (!$this->is_remote_plugin_available($component, $version, true)) {
            $reason = 'remoteunavailable';
            return false;
        }

        // Make sure the plugin type root directory is writable.
        list($plugintype, $pluginname) = core_component::normalize_component($component);
        if (!$this->is_plugintype_writable($plugintype)) {
            $reason = 'notwritableplugintype';
            return false;
        }

        $remoteinfo = $this->get_remote_plugin_info($component, $version, true);
        $localinfo = $this->get_plugin_info($component);

        if ($localinfo) {
            // If the plugin is already present, prevent downgrade.
            if ($localinfo->versiondb > $remoteinfo->version->version) {
                $reason = 'cannotdowngrade';
                return false;
            }

            // Make sure we have write access to all the existing code.
            if (is_dir($localinfo->rootdir)) {
                if (!$this->is_plugin_folder_removable($component)) {
                    $reason = 'notwritableplugin';
                    return false;
                }
            }
        }

        // Looks like it could work.
        return true;
    }