*

Web

  • ****
  • 183 posts
daily sending email
« on: October 20, 2020, 12:27:59 PM »
@mbthemes

daily sending email your website has been auto-upgraded

old version 411
current version 411

*

MB Themes

Re: daily sending email
« Reply #1 on: October 20, 2020, 03:45:18 PM »
@Web
Go to oc-includes/osclass/utils.php find osc_do_auto_upgrade() function and replace it with following.
Problem here what I see is that mail can be sent even no upgrade has been made, as well as email inform about core updates, but theme, plugin or lanugage update could be made.

Code: [Select]
function osc_do_auto_upgrade()
{
  $data = osc_file_get_contents('https://osclass.osclasspoint.com/api/latest_version.php');
  //$data = preg_replace('|^\?\((.*?)\);$|', '$01', $data);
  $json = json_decode($data, true);
  $result = array();
  $result['error'] = 0;
  $old_version = osc_version();
  $themes_updated = 0;
  $plugins_updated = 0;
  $languages_updated = 0;
  $core_updated = 0;

  if (isset($json['version'])) {
    if ($json['version'] > osc_version()) {
      osc_set_preference('update_core_json', json_decode($data));

      if (osc_check_dir_writable()) {
        if (strpos($json['version'], substr(osc_version(), 0, 1)) !== 0) {
          // NEW BRANCH
          if (strpos(osc_auto_update(), 'branch') !== false) {
            osc_run_hook('before_auto_upgrade');
            $result = osc_do_upgrade();
            $core_updated = 1;
            osc_run_hook('after_auto_upgrade', $result);
          }
        } elseif (substr($json['version'], 1, 1) !== substr(osc_version(), 1, 1)) {
          // MAJOR RELEASE
          if (strpos(osc_auto_update(), 'branch') !== false || strpos(osc_auto_update(), 'major') !== false) {
            osc_run_hook('before_auto_upgrade');
            $result = osc_do_upgrade();
            $core_updated = 1;
            osc_run_hook('after_auto_upgrade', $result);
          }
        } elseif (substr($json['version'], 2, 1) !== substr(osc_version(), 2, 1)) {
          // MINOR RELEASE
          if (strpos(osc_auto_update(), 'branch') !== false || strpos(osc_auto_update(), 'major') !== false
            || strpos(osc_auto_update(), 'minor') !== false
          ) {
            osc_run_hook('before_auto_upgrade');
            $result = osc_do_upgrade();
            $core_updated = 1;
            osc_run_hook('after_auto_upgrade', $result);
          }
        }
      }
    } else {
      osc_set_preference('update_core_json');
    }
    osc_set_preference('last_version_check', time());
  } else {
    osc_set_preference('update_core_json');
    osc_set_preference('last_version_check', time() - 23 * 3600);
  }

  // core has been updated correctly or there was no core update at all
  if ($result['error'] == 0 || $result['error'] == 6) {
    if (strpos(osc_auto_update(), 'plugins') !== false) {
      $total = osc_check_plugins_update(true);
      if ($total > 0) {
        $elements = osc_get_preference('plugins_to_update');
        foreach ($elements as $element) {   // element is product key
          if (osc_is_update_compatible('check_version', $element, $json['version_string'])) {
            osc_market('plugins', $element);
            $plugins_updated = $total;
          }
        }
      }
    }

    if (strpos(osc_auto_update(), 'themes') !== false) {
      $total = osc_check_themes_update(true);
      if ($total > 0) {
        $elements = osc_get_preference('themes_to_update');
        foreach ($elements as $element) {   // element is product key
          if (osc_is_update_compatible('check_version', $element, $json['version_string'])) {
            osc_market('themes', $element);
            $themes_updated = $total;
          }
        }
      }
    }

    if (strpos(osc_auto_update(), 'languages') !== false) {
      $total = osc_check_languages_update(true);
      if ($total > 0) {
        $elements = osc_get_preference('languages_to_update');
        foreach ($elements as $element) {    // element is language code
          $lang_row = OSCLocale::newInstance()->findByCode($element);
          if (!isset($lang_row['s_version']) || osc_is_update_compatible('languages', $element, @$lang_row['s_version'])) {
            osc_market('languages', $element);
            $languages_updated = $total;
          }
        }
      }
    }


    // notify site admin
    if($core_updated > 0 || $plugins_updated > 0 || $themes_updated > 0 || $languages_updated) {
      $title = __('[{WEB_TITLE}] has been auto-upgraded');

      $body  = '<p>' . __('Hi Admin!') . '</p>';
      $body .= '<p>' . __('Let us inform you, that your osclass website {WEB_TITLE} on {WEB_URL} has been auto-upgraded. List of upgraded items is bellow.') . '</p>';

      if($core_updated > 0) {
        $body .= '<p>' . __('Osclass core has been updated') . '</p>';
        $body .= '<p>' . __('Old version') . ': <strong>{OLD_VERSION}</strong></p>';
        $body .= '<p>' . __('Current version') . ': <strong>{NEW_VERSION}</strong></p>';
      }

      if($plugins_updated > 0) {
        $body .= '<p>' . sprintf(__('%s plugin(s) has been updated'), '<strong>' . $plugins_updated . '</strong>') . '</p>';
      }

      if($themes_updated > 0) {
        $body .= '<p>' . sprintf(__('%s theme(s) has been updated'), '<strong>' . $themes_updated . '</strong>') . '</p>';
      }

      if($languages_updated > 0) {
        $body .= '<p>' . sprintf(__('%s plugin(s) has been updated'), '<strong>' . $languages_updated . '</strong>') . '</p>';
      }

      $body .= '<p><br/></p>';
      $body .= '<p>' . __('This is an automatic email, if you already did that, please ignore this email.') . '</p>';
      $body .= '<p>' . __('Thank you') . ', <br />{WEB_TITLE}</p>';

      $words = array();
      $words[] = array('{WEB_TITLE}', '{WEB_URL}', '{OLD_VERSION}', '{NEW_VERSION}');
      $words[] = array(osc_page_title(), osc_base_url(), $old_version, $json['version']);

      $title = osc_mailBeauty($title, $words);
      $body  = osc_mailBeauty($body, $words);
   
      $emailParams = array(
        'subject' => $title,
        'to' => osc_contact_email(),
        'to_name' => __('Admin'),
        'body' => $body,
        'alt_body' => $body
      );

      osc_sendMail($emailParams);
    }
  }
}
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots