[fusionregistry-commitlog] SF.net SVN: fusionregistry: [34] branches/stable_3_0_x/upload/sources
Brought to you by:
copland007
From: SVN c. <fus...@li...> - 2008-02-10 07:18:59
|
Revision: 34 http://fusionregistry.svn.sourceforge.net/fusionregistry/?rev=34&view=rev Author: copland007 Date: 2008-02-09 23:19:03 -0800 (Sat, 09 Feb 2008) Log Message: ----------- Introduced make/model cache 'registry_makemodel'. Implemented on 'add new item' and all acp make/model pages that modify database tables. Added an on-demand rebuild of registry_makemodel cache tool. Modified Paths: -------------- branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_makes_models.php branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/functions.php Modified: branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_makes_models.php =================================================================== --- branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_makes_models.php 2008-02-10 05:28:00 UTC (rev 33) +++ branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_makes_models.php 2008-02-10 07:19:03 UTC (rev 34) @@ -46,6 +46,7 @@ */ require_once( AD_REGISTRY_PATH.'ad_registry_loader.php' ); require_once( REGISTRY_PATH.'lib/custom_fields.php' ); +require_once( REGISTRY_PATH.'lib/functions.php' ); /** * Class ad_registry_makes_models deals with the vehicle makes & models of the Fusion Registry @@ -89,9 +90,11 @@ $this->ad_registry_loader->ipsclass =& $this->ipsclass; $this->ad_registry_loader->auto_run(&$this); - // Initialize custom_fields + // Initialize custom_fields and functions $this->lib['custom_fields'] = new registry_custom_fields(&$class); $this->lib['custom_fields']->ipsclass =& $this->ipsclass; + $this->lib['functions'] = new registry_functions(&$class); + $this->lib['functions']->ipsclass =& $this->ipsclass; switch($this->ipsclass->input['code']) { @@ -176,6 +179,9 @@ $added_makes .= "$make, "; } + // Rebuild cache + $this->lib['functions']->update_makemodel_cache(); + $added_makes = substr($added_makes, 0, -2); $text = "Added Fusion Registry Vehicle Make(s) '$added_makes'"; @@ -230,6 +236,9 @@ $added_models .= "$model, "; } + // Rebuild cache + $this->lib['functions']->update_makemodel_cache(); + $added_models = substr($added_models, 0, -2); $text = "Added Fusion Registry Vehicle Model(s) '$added_models'"; @@ -522,6 +531,9 @@ $this->ipsclass->DB->query("UPDATE ibf_registry_makes SET $db_string WHERE id='".$this->ipsclass->input['make_id']."'"); + // Rebuild cache + $this->lib['functions']->update_makemodel_cache(); + $text = "Modified Fusion Registry Make ID: '{$this->ipsclass->input['make_id']}' to '{$this->ipsclass->input['change_to']}'"; $url = 'act='.REGISTRY_URL.'§ion=components&menu=makes_models&code=make_menu'; $time = 2; @@ -552,6 +564,9 @@ $this->ipsclass->DB->query("UPDATE ibf_registry_models SET $db_string WHERE id='".$this->ipsclass->input['model_id']."'"); + // Rebuild cache + $this->lib['functions']->update_makemodel_cache(); + $text = "Modified Fusion Registry Model ID: '{$this->ipsclass->input['model_id']}' to '{$this->ipsclass->input['change_to']}'"; $url = 'act='.REGISTRY_URL.'§ion=components&menu=makes_models&code=model_menu&make_id='. $this->ipsclass->input['make_id']; $time = 2; @@ -719,6 +734,9 @@ // Delete any models of this make $this->ipsclass->DB->query("DELETE FROM ibf_registry_models WHERE make_id IN $sql_make_ids"); + // Rebuild cache + $this->lib['functions']->update_makemodel_cache(); + $text = "Deleted Fusion Registry Vehicle Make '$make_to_delete' and Models"; $url = 'act='.REGISTRY_URL.'§ion=components&menu=makes_models&code=make_menu'; $time = 2; @@ -886,6 +904,9 @@ // Bye-Bye... delete the model $this->ipsclass->DB->query("DELETE FROM ibf_registry_models WHERE id IN $sql_model_ids"); + // Rebuild cache + $this->lib['functions']->update_makemodel_cache(); + $text = "Deleted Fusion Registry Vehicle Model '$model_to_delete'"; $url = 'act='.REGISTRY_URL.'§ion=components&menu=makes_models&code=model_menu&make_id='. $this->ipsclass->input['make_id']; $time = 2; Modified: branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php =================================================================== --- branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php 2008-02-10 05:28:00 UTC (rev 33) +++ branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php 2008-02-10 07:19:03 UTC (rev 34) @@ -46,6 +46,7 @@ */ require_once( AD_REGISTRY_PATH.'ad_registry_loader.php' ); require_once( KERNEL_PATH.'class_image.php' ); +require_once( REGISTRY_PATH.'lib/functions.php' ); /**#@-*/ /** @@ -109,6 +110,10 @@ $this->db_remove_1742529(); break; + case 'rebuild_makemodel_cache': + $this->rebuild_makemodel_cache(); + break; + default: $this->main_menu(); break; @@ -401,6 +406,29 @@ /** + * Rebuild make/model cache + */ + function rebuild_makemodel_cache() + { + $registry_funcs = new registry_functions(); + $registry_funcs->ipsclass =& $this->ipsclass; + + $registry_funcs->update_makemodel_cache(); + + // Report our mischief ways :) + $text = "<b>Fusion Registry make/model cache rebuilt</b>"; + $url = "act=".REGISTRY_URL."§ion=components&menu=tools"; + $time = 5; + + // Big brother is watching :) + $this->ipsclass->admin->save_log("Rebuilt Fusion Registry make/model cache"); + + // End of the show, c'ya + $this->ipsclass->admin->redirect( $url, $text, 0, $time ); + } + + + /** * Rebuild All Thumbnails * * If the end user opted to create a log we will use function {@link _log} @@ -916,6 +944,26 @@ $this->ipsclass->html .= $this->ipsclass->adskin->end_table(); + $this->ipsclass->html .= '<br />'; + + //------------------------------- + // Rebuild make/model cache tool + //------------------------------- + + $this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code', 'rebuild_makemodel_cache' ), + 2 => array( 'act' , REGISTRY_URL ), + 3 => array( 'menu', 'tools' ), + 4 => array( 'section', 'components' ), + ) ); + + $desc = 'The rebuild make/model cache tool will refresh the cache of all the makes and models in the database.'; + + $this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Rebuild make/model cache", $desc ); + + $this->ipsclass->html .= $this->ipsclass->adskin->end_form('Rebuild make/model cache'); + + $this->ipsclass->html .= $this->ipsclass->adskin->end_table(); + // That's all folk! $this->ipsclass->admin->output(); } Modified: branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/functions.php =================================================================== --- branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/functions.php 2008-02-10 05:28:00 UTC (rev 33) +++ branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/functions.php 2008-02-10 07:19:03 UTC (rev 34) @@ -180,26 +180,24 @@ $return = ''; - $make_q_id = $this->ipsclass->DB->query("SELECT id, make FROM ibf_registry_makes ORDER BY make ASC"); + // Load the cache + $this->ipsclass->init_load_cache( array( 'registry_makemodel' ) ); // Loop through all the makes - while ( $make_row = $this->ipsclass->DB->fetch_row($make_q_id) ) + foreach ( $this->ipsclass->cache['registry_makemodel'] as $make_id => $make_array ) { // Start this makes' row in the output, this is where it gets confusing! - $return .= 'cars["'.$make_row['make'].'"] = new Array("'.$make_row['id'].'", new Array('; + $return .= 'cars["'.$make_array['name'].'"] = new Array("'.$make_id.'", new Array('; - $model_q_id = $this->ipsclass->DB->query("SELECT id, model FROM ibf_registry_models - WHERE make_id='".$make_row['id']."' ORDER BY model ASC"); - $model_string = ''; $model_id_string = ''; // Loop through all the models of this make - while ( $model_row = $this->ipsclass->DB->fetch_row($model_q_id) ) + foreach ( $make_array['models'] as $model_id => $model_name ) { // Create the arrays that we will use in the output - $model_string .= '"'.$model_row['model'].'",'; - $model_id_string .= '"'.$model_row['id'] .'",'; + $model_string .= '"'.$model_name.'",'; + $model_id_string .= '"'.$model_id .'",'; } // Strip off the last comma @@ -375,6 +373,40 @@ return TRUE; } + + /** + * Update/Rebuild make and model cache + * + * This gets run any time a change is made to makes/models, and + * on demand in the ACP tools. + */ + function update_makemodel_cache() + { + // Start with an empty cache + $this->ipsclass->cache['registry_makemodel'] = array(); + + // Loop through each make + $make_q_id = $this->ipsclass->DB->query("SELECT id, make FROM ibf_registry_makes"); + + // Loop through all the makes + while ( $make_row = $this->ipsclass->DB->fetch_row($make_q_id) ) + { + // Create the base make entry + $this->ipsclass->cache['registry_makemodel'][ $make_row['id'] ] = array( 'name' => $make_row['make'], + 'models' => array() ); + + $model_q_id = $this->ipsclass->DB->query("SELECT id, model FROM ibf_registry_models WHERE make_id='".$make_row['id']."'"); + + // Loop through all the models of this make + while ( $model_row = $this->ipsclass->DB->fetch_row($model_q_id) ) + { + $this->ipsclass->cache['registry_makemodel'][ $make_row['id'] ]['models'][ $model_row['id'] ] = $model_row['model']; + } + } + + // Save it back to the cache_store + $this->ipsclass->update_cache( array( 'name' => 'registry_makemodel', 'array' => 1, 'deletefirst' => 1, 'donow' => 0 ) ); + } } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |