Configuration cache install for osCommerce 2.3.3

 

1) Copy the configuration_cache_write.php file to the appropriate place and create a folder named cache inside the catalog/includes folder. Set the permissions on the new cache folder to the least permissive that will allow PHP to write to the folder. Try permissions 755 first, then if that doesn't work try 775 and use 777 only if you have no other choice. It is highly recommended that you secure this folder either by using .htaccess or by updating settings in the httpd.conf file for your server. While the cache create function will attempt to create the cache folder if it does not exist chances are good that the attempt will fail since the catalog/includes folder will probably not be writable by PHP.

 

2) In catalog/includes/configure.php

 

ADD before the closing ?>

 

define('DIR_WS_CACHE', DIR_WS_INCLUDES . 'cache/');

 

3) In catalog/admin/includes/configure.php

 

ADD before the closing ?>

 

define('DIR_FS_PHPCACHE', DIR_FS_CATALOG . 'includes/cache/');

 

4) In BOTH catalog/includes/filenames.php AND catalog/admin/includes/filenames.php

 

ADD before the closing ?>

 

// configuration cache

  define('FILENAME_CONFIG_CACHE', 'configuration_cache.php');

 

5) In catalog/admin/includes/application_top.php

 

FIND around line 65:

 

// set application wide parameters

  $configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);

  while ($configuration = tep_db_fetch_array($configuration_query)) {

    define($configuration['cfgKey'], $configuration['cfgValue']);

  }

 

REPLACE with:

 

// set application wide parameters

  $success = include(DIR_FS_PHPCACHE . FILENAME_CONFIG_CACHE);

  if ($success != 'Configuration Cache Success') {

    $configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);

    while ($configuration = tep_db_fetch_array($configuration_query)) {

      define($configuration['cfgKey'], $configuration['cfgValue']);

    }

  }

 

6) In catalog/includes/application_top.php

 

FIND around line 68:

 

// set the application parameters

  $configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);

  while ($configuration = tep_db_fetch_array($configuration_query)) {

    define($configuration['cfgKey'], $configuration['cfgValue']);

  }

 

REPLACE with:

 

// set the application parameters

  $success = include(DIR_WS_CACHE . FILENAME_CONFIG_CACHE);

  if ($success != 'Configuration Cache Success') {

    $configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);

    while ($configuration = tep_db_fetch_array($configuration_query)) {

      define($configuration['cfgKey'], $configuration['cfgValue']);

    }

  }

 

7) In catalog/admin/includes/languages/english.php

 

ADD before the closing ?>

 

// configuration cache

define('ERROR_CONFIG_CACHE_WRITE', 'Attempt to write configuration cache file failed!');

 

8) In catalog/admin/configuration.php

 

FIND near the top of the file:

 

  if (tep_not_null($action)) {

    switch ($action) {

      case 'save':

        $configuration_value = tep_db_prepare_input($HTTP_POST_VARS['configuration_value']);

        $cID = tep_db_prepare_input($HTTP_GET_VARS['cID']);

 

        tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($configuration_value) . "', last_modified = now() where configuration_id = '" . (int)$cID . "'");

 

        tep_redirect(tep_href_link(FILENAME_CONFIGURATION, 'gID=' . $HTTP_GET_VARS['gID'] . '&cID=' . $cID));

        break;

    }

  }

 

ADD BETWEEN the tep_db_query and the tep_redirect statements:

 

        // write configuration cache

        include(DIR_WS_FUNCTIONS . 'configuration_cache_write.php');

        if (!write_configuration_cache_file()) {

          $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

        }

 

The section should now look like this:

 

  if (tep_not_null($action)) {

    switch ($action) {

      case 'save':

        $configuration_value = tep_db_prepare_input($HTTP_POST_VARS['configuration_value']);

        $cID = tep_db_prepare_input($HTTP_GET_VARS['cID']);

 

        tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($configuration_value) . "', last_modified = now() where configuration_id = '" . (int)$cID . "'");

       

        // write configuration cache

        include(DIR_WS_FUNCTIONS . 'configuration_cache_write.php');

        if (!write_configuration_cache_file()) {

          $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

        }

 

        tep_redirect(tep_href_link(FILENAME_CONFIGURATION, 'gID=' . $HTTP_GET_VARS['gID'] . '&cID=' . $cID));

        break;

    }

  }

 

9) In catalog/admin/modules.php

 

9a) FIND near the beginning of the file:

 

      case 'save':

        reset($HTTP_POST_VARS['configuration']);

        while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {

          tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");

        }

        tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));

        break;

 

ADD IMMEDIATELY BEFORE the tep_redirect statement:

 

        // write configuration cache

        if (!write_configuration_cache_file()) {

          $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

        }

 

9b) Just below this FIND the section reading:

 

          if ($action == 'install') {

            $module->install();

 

            $modules_installed = explode(';', constant($module_key));

            $modules_installed[] = $class . $file_extension;

            tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . implode(';', $modules_installed) . "' where configuration_key = '" . $module_key . "'");

            tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $class));

          } elseif ($action == 'remove') {

            $module->remove();

 

            $modules_installed = explode(';', constant($module_key));

            unset($modules_installed[array_search($class . $file_extension, $modules_installed)]);

            tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . implode(';', $modules_installed) . "' where configuration_key = '" . $module_key . "'");

            tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set));

          }

 

and again ADD IMMEDIATELY BEFORE BOTH tep_redirect statements:

 

            // write configuration cache

            if (!write_configuration_cache_file()) {

              $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

            }

 

The action section of the modules.php file should now look like this:

 

  if (tep_not_null($action)) {

    switch ($action) {

      case 'save':

        reset($HTTP_POST_VARS['configuration']);

        while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {

          tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");

        }

        // write configuration cache

        include(DIR_WS_FUNCTIONS . 'configuration_cache_write.php');

        if (!write_configuration_cache_file()) {

          $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

        }

        tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));

        break;

      case 'install':

      case 'remove':

        $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));

        $class = basename($HTTP_GET_VARS['module']);

        if (file_exists($module_directory . $class . $file_extension)) {

          include($module_directory . $class . $file_extension);

          $module = new $class;

          if ($action == 'install') {

            $module->install();

 

            $modules_installed = explode(';', constant($module_key));

            $modules_installed[] = $class . $file_extension;

            tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . implode(';', $modules_installed) . "' where configuration_key = '" . $module_key . "'");

            // write configuration cache

            if (!write_configuration_cache_file()) {

              $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

            }

            tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $class));

          } elseif ($action == 'remove') {

            $module->remove();

 

            $modules_installed = explode(';', constant($module_key));

            unset($modules_installed[array_search($class . $file_extension, $modules_installed)]);

            tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . implode(';', $modules_installed) . "' where configuration_key = '" . $module_key . "'");

            // write configuration cache

            if (!write_configuration_cache_file()) {

              $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

            }

            tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set));

          }

        }

        tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $class));

        break;

    }

  }

 

9c) Now scroll down towards the end of the file and FIND:

 

        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Installed Template Block Groups', 'TEMPLATE_BLOCK_GROUPS', '" . $module_type . "', 'This is automatically updated. No need to edit.', '6', '0', now())");

      }

    }

  }

?>

              <tr>

                <td colspan="3" class="smallText"><?php echo TEXT_MODULE_DIRECTORY . ' ' . $module_directory; ?></td>

              </tr>

 

ADD just BEFORE the LAST closing brace (}):

 

    // write configuration cache

    if (!write_configuration_cache_file()) {

      $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

    }

 

The section of code should now look like this:

 

        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Installed Template Block Groups', 'TEMPLATE_BLOCK_GROUPS', '" . $module_type . "', 'This is automatically updated. No need to edit.', '6', '0', now())");

      }

    }

    // write configuration cache

    if (!write_configuration_cache_file()) {

      $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

    }

  }

?>

              <tr>

                <td colspan="3" class="smallText"><?php echo TEXT_MODULE_DIRECTORY . ' ' . $module_directory; ?></td>

              </tr>

 

9d) At the very beginning of the file FIND:

 

  require('includes/application_top.php');

 

ADD immediately BELOW it:

 

  require(DIR_WS_FUNCTIONS . 'configuration_cache_write.php');

 

 

10) In catalog/admin/modules_content.php

 

10a) At the very beginning of the file FIND:

 

  require('includes/application_top.php');

 

ADD immediately BELOW it:

 

  require(DIR_WS_FUNCTIONS . 'configuration_cache_write.php');

 

10b) FIND near the beginning of the file:

 

  if (tep_not_null($action)) {

    switch ($action) {

 

ADD IMMEDIATELY BEFORE every tep_redirect statement for each case (five total):

 

        // write configuration cache

        if (!write_configuration_cache_file()) {

          $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

        }

 

The action section of the modules_content.php file should now look like this:

 

  if (tep_not_null($action)) {

    switch ($action) {

      case 'save':

        $class = basename($HTTP_GET_VARS['module']);

 

        foreach ( $modules['installed'] as $m ) {

          if ( $m['code'] == $class ) {

            foreach ($HTTP_POST_VARS['configuration'] as $key => $value) {

              $key = tep_db_prepare_input($key);

              $value = tep_db_prepare_input($value);

 

              tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($value) . "' where configuration_key = '" . tep_db_input($key) . "'");

            }

 

            break;

          }

        }

 

        if (!write_configuration_cache_file()) {

          $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

        }

        tep_redirect(tep_href_link('modules_content.php', 'module=' . $class));

 

        break;

 

      case 'install':

        $class = basename($HTTP_GET_VARS['module']);

 

        foreach ( $modules['new'] as $m ) {

          if ( $m['code'] == $class ) {

            $module = new $class();

 

            $module->install();

 

            $modules_installed[] = $m['group'] . '/' . $m['code'];

 

            tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . implode(';', $modules_installed) . "' where configuration_key = 'MODULE_CONTENT_INSTALLED'");

 

            if (!write_configuration_cache_file()) {

              $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

            }

            tep_redirect(tep_href_link('modules_content.php', 'module=' . $class . '&action=edit'));

          }

        }

 

        if (!write_configuration_cache_file()) {

          $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

        }

        tep_redirect(tep_href_link('modules_content.php', 'action=list_new&module=' . $class));

 

        break;

 

      case 'remove':

        $class = basename($HTTP_GET_VARS['module']);

 

        foreach ( $modules['installed'] as $m ) {

          if ( $m['code'] == $class ) {

            $module = new $class();

 

            $module->remove();

 

            $modules_installed = explode(';', MODULE_CONTENT_INSTALLED);

 

            if (in_array($m['group'] . '/' . $m['code'], $modules_installed)) {

              unset($modules_installed[array_search($m['group'] . '/' . $m['code'], $modules_installed)]);

            }

 

            tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . implode(';', $modules_installed) . "' where configuration_key = 'MODULE_CONTENT_INSTALLED'");

 

            if (!write_configuration_cache_file()) {

              $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

            }

            tep_redirect(tep_href_link('modules_content.php'));

          }

        }

 

        if (!write_configuration_cache_file()) {

          $messageStack->add_session(ERROR_CONFIG_CACHE_WRITE);

        }

        tep_redirect(tep_href_link('modules_content.php', 'module=' . $class));

 

        break;

    }

  }

 

 

11) To activate the contribution simply edit and save any configuration or module setting, no actual change is necessary.

 

NOTE: If you install any contributions that have you load values directly into the configuration table using phpMyAdmin or any other directly run SQL statements remember to reload the configuration cache as per step 11 above.