public function deployRelease($rest)
 {
     $post = $rest->getRequest()->getPost();
     MM_LogApi::logRequest(json_encode($post), "/deployRelease");
     if (!isset($post["version"])) {
         return new Response($rest, "Major version number is required", RESPONSE_ERROR_MESSAGE_MISSING_PARAMS . " : version", RESPONSE_ERROR_CODE_MISSING_PARAMS, RESPONSE_ERROR_MESSAGE_MISSING_PARAMS);
     }
     $majorVersion = $post["version"];
     $minorVersion = isset($post["minor_version"]) ? $post["minor_version"] : MM_MemberMouseService::$DEFAULT_MINOR_VERSION;
     $crntVersion = MemberMouse::getPluginVersion();
     if ($crntVersion != $majorVersion) {
         MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_UPGRADE_NOTICE, $majorVersion);
         return new Response($rest, "Major version do not match. A notification will be displayed to the customer informing them an update is available.", "Major version do not match. A notification will be displayed to the customer informing them an update is available.", RESPONSE_ERROR_CODE_BAD_REQUEST, RESPONSE_ERROR_MESSAGE_MISSING_PARAMS);
     }
     // if major versions match, update cache with the latest files from central
     $writeableDir = MM_Utils::getCacheDir();
     // delete existing cache
     if (is_dir($writeableDir)) {
         if (is_writeable($writeableDir)) {
             if ($handle = opendir($writeableDir)) {
                 while (false !== ($file = readdir($handle))) {
                     if (!is_dir($file)) {
                         @unlink($writeableDir . "/" . $file);
                     }
                 }
                 closedir($handle);
             }
         }
     }
     // get updated classes from central
     MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_MINOR_VERSION, $minorVersion);
     $ret = MM_MemberMouseService::authorize(true);
     if (MM_Response::isError($ret)) {
         return new Response($rest, "Could not find classes associated with version {$majorVersion}.{$minorVersion}", "Invalid major/minor version combination", RESPONSE_ERROR_CODE_BAD_REQUEST, RESPONSE_ERROR_MESSAGE_MISSING_PARAMS);
     }
     if (defined("DB_NAME")) {
         global $wpdb;
         if (file_exists($writeableDir . "/membermouse_schema.sql")) {
             $phpObj = new MM_PhpObj($wpdb, DB_NAME);
             if (!$phpObj->importFile($writeableDir . "/membermouse_schema.sql", true)) {
                 return new Response($rest, "Could not update MemberMouse database", "Could not update MemberMouse database", RESPONSE_ERROR_CODE_BAD_REQUEST, RESPONSE_ERROR_MESSAGE_MISSING_PARAMS);
             }
         }
     } else {
         return new Response($rest, "DB_NAME not defined", "DB_NAME not defined", RESPONSE_ERROR_CODE_BAD_REQUEST, RESPONSE_ERROR_MESSAGE_MISSING_PARAMS);
     }
     $version = $majorVersion;
     if (!empty($minorVersion)) {
         $version .= "-" . $minorVersion;
     }
     $versionRelease = MM_VersionRelease::findByVersion($version);
     $versionRelease->setVersion($version);
     $versionRelease->commitData();
     return new Response($rest);
 }
Example #2
0
 public function activate()
 {
     global $wpdb;
     ob_start();
     $error = "";
     if ($this->createDBCache()) {
         if ($this->updateMemberMouseClass()) {
             // reset minor version if this is a major version upgrade
             $crntMajorVersion = MemberMouse::getPluginVersion();
             $lastMajorVersion = MM_OptionUtils::getOption(MM_OptionUtils::$OPTION_KEY_MAJOR_VERSION);
             if (!empty($lastMajorVersion) && version_compare($lastMajorVersion, $crntMajorVersion) < 0) {
                 MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_MINOR_VERSION, MM_MemberMouseService::$DEFAULT_MINOR_VERSION);
             }
             if ($this->authenticateWithMM() !== false) {
                 if ($this->alterMMTables()) {
                     $this->temporaryRestoreOrderItemAccessPatch();
                     $this->temporaryPendingOverdueSubscriptionPatch();
                     $this->populateOriginAffiliateIds();
                     if ($this->insertMMDefaultData()) {
                         // set new major version
                         $crntMajorVersion = MemberMouse::getPluginVersion();
                         MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_MAJOR_VERSION, $crntMajorVersion);
                         //update version history
                         $versionDescription = $crntMajorVersion;
                         $minorVersion = MM_OptionUtils::getOption(MM_OptionUtils::$OPTION_KEY_MINOR_VERSION);
                         if ($minorVersion !== false && intval($minorVersion) > 0) {
                             $versionDescription .= "-" . $minorVersion;
                         } else {
                             $versionDescription .= "-" . MM_MemberMouseService::$DEFAULT_MINOR_VERSION;
                         }
                         $versionRelease = MM_VersionRelease::findByVersion($versionDescription);
                         $versionRelease->setVersion($versionDescription);
                         $versionRelease->commitData();
                         MM_MemberMouseService::activatePlugin();
                         // clear major version notice
                         $crntMajorVersion = MemberMouse::getPluginVersion();
                         $upgradeVersion = MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_UPGRADE_NOTICE);
                         if (!empty($upgradeVersion) && version_compare($crntMajorVersion, $upgradeVersion, ">=")) {
                             MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_UPGRADE_NOTICE, "");
                         }
                         ob_end_clean();
                         return true;
                     } else {
                         $error = "Could not install default data.";
                     }
                 } else {
                     $error = "Could not alter MemberMouse tables.";
                 }
             } else {
                 $error = "<div style='font-family: sans-serif; font-size: 13px;'>";
                 $error .= "<h3 style='color:#BC0B0B; margin-top:0px; margin-bottom:5px; font-size: 14px;'>This site is not authorized to use the MemberMouse plugin</h3>";
                 $error .= "<p style='margin-top:0px; margin-bottom:5px;'>In order to use the MemberMouse plugin you need to <a href=\"https://membermouse.uservoice.com/knowledgebase/articles/319186-installing-membermouse\" target=\\_blank\">register your site with membermouse.com</a>.</p>";
                 $error .= "</div>";
             }
         } else {
             $error = "Could not insert MM_MemberMouseService into DB cache";
         }
     } else {
         $error = "Could not create DB cache";
     }
     ob_end_clean();
     // an error occurred so deactivate the plugin
     $this->showError($error);
     exit;
 }