Page 1 of 1

[SOLVED] 1.11.7 broken after move - global content goes AWOL

Posted: Thu Sep 12, 2013 5:30 am
by rotezecke
a second issue that i think i should post separately. same background story:

my host copied a CMSMS 1.11.7 website to a new server.

after i call certain pages, things seem to go crazy, which looks like global content blocks cannot be found. instead I see this in html

Code: Select all

<!-- Html blob 'JS_head' does not exist  -->
i also found this in admin log:
Global Content Block: system calculation warning
Can not open or does not exist!

note the GCB is actually named (and correctly called) system_calculation_warning

I assume there's a UDT that causes all this. if anyone has experienced similar issues i'd like to hear from you. cheers,

Re: 1.11.7 broken after move - global content blocks go AWOL

Posted: Thu Sep 12, 2013 6:03 am
by rotezecke
I think I dont close database connections properly as debug shows that I'm trying to retrieve the data from the wrong database. I have multiple UDTs that access different databases, and in the past I didnt use mysql_close() as it always worked without. is there a CMSMS way to reconnect to its native database (for UDT)?

Re: 1.11.7 broken after move - global content blocks go AWOL

Posted: Thu Sep 12, 2013 6:17 am
by rotezecke
adodb_connect();

at end of UDTs makes a difference! How did it ever work without?

Re: 1.11.7 broken after move - global content blocks go AWOL

Posted: Thu Sep 12, 2013 12:03 pm
by Owens
rotezecke wrote:adodb_connect();

at end of UDTs makes a difference! How did it ever work without?
You are correct.

Your UDTs that are using a different database should then use adodb_connect() to re-establish connections to the primary database that is setup for CMSMS.

I only know that because I've run into the same problem before ;p

Sorry it took me so long to respond to your question. Looks like you have it all sorted.

Re: [SOLVED] 1.11.7 broken after move - global content goes

Posted: Thu Sep 12, 2013 2:48 pm
by Rolf
rotezecke wrote:i also found this in admin log:
Global Content Block: system calculation warning
Can not open or does not exist!
Nice hehh :)

Re: 1.11.7 broken after move - global content blocks go AWOL

Posted: Tue Feb 18, 2014 9:58 am
by Rolf
rotezecke wrote:adodb_connect();

at end of UDTs makes a difference! How did it ever work without?
What is the content of that UDT, Rotezecke?

Re: [SOLVED] 1.11.7 broken after move - global content goes

Posted: Tue Feb 18, 2014 4:31 pm
by rotezecke
I'm not sure anymore, I have about 20 UDTs that access another database, 3 or 4 of them were playing up after I moved the site to a new server. adding "adodb_connect();" at the end fixed the problem for all of them. However, some of my UDTs did not require this, but I ended up adding that line to all of them. The only other time I observed this problem is described here http://forum.cmsmadesimple.org/viewtopi ... 48#p307348
but tristan was correct, my subsequent edit only triggered a cache refresh as I couldnt reproduce the problem when I rolled back the code.
here's a UDT that I believe stopped working at the time:

Code: Select all

//create link using (duplicated) SEO_URL logic
//script completely ignores SEO_URL backend settings
//ms 5.11.13
//requires products ID as params['id']
//optional:
//text, assign 
//warning emails go to:
$webmaster = 'webdude@xxxxx';
// ------------------ dont edit below unless you know what you're doing --------------
//get database credentials
require "ms_config/db.php";
//connect - using ADOdb lite syntax
$db = NewADOConnection('mysql');
$db->Connect($db_host,$db_user,$db_pw,$db_db);
//products_id
$product = array((int)$params['id']);
//only active products, dont bother about language settings
$query = "SELECT products_name as pName, products_seo_url as psu FROM products_description pd JOIN products p ON pd.products_id = p.products_id WHERE pd.products_id = ? AND p.products_status = '1'";

$result = $db->GetArray($query,$product);

//send email on error
$error = false;
if (!$result  ) {
    $error=true;
    $msg = 'Check product ID '.$product[0]. ' found on page (alias): '. $smarty->get_template_vars('page_alias');
    mail($webmaster,'Error by osc_product_link UDT',$msg); 
} else {
$row = $result;
//no error
//no URL? use name instead
     if($row[0]['psu'] != '') {
	$pName = $row[0]['psu'];
     } else {
        $pName = $row[0]['pName'];				  
     }
//strip most special characters (not the underscore)
     $pattern = "/([^a-zA-Z0-9_[:space:]])+/";
     $anchor = preg_replace($pattern, '', trim(strtolower($pName)));
//replace with - dashes
     $pattern = "/([[:space:]]|[[:blank:]])+/"; 
     $anchor = preg_replace($pattern, '-', $anchor); 
//strip short words ($limit), unless separated with underscores
     $limit = 3;
     $foo = @explode('-', $anchor);
     foreach($foo as $index => $value){
	switch (true){
		case ( strlen($value) <= $limit ):
			continue;
		default:
			$container[] = $value;
			break;
	}		
     } 
     $container = ( sizeof($container) > 1 ? implode('-', $container) : $anchor );
     $container = str_replace('_','-',$container);
     //get root url
     $config = cmsms()->GetConfig();	
     $seo_url = $config['root_url'] . "/catalog/".$container ."-p-".$product[0] .".html";
     if($params['text'] != '') {
           $seo_url = '<a href="'.$seo_url.'">'.$params['text'].'</a>';
     }
}
//assign results or print to screen
if(isset($params['assign']) && $params['assign'] != '' && !$error) {
     $smarty->assign($params['assign'], $seo_url);
} else if(isset($params['assign']) && $params['assign'] != '' && $error && $params['text'] != '') {
     $smarty->assign($params['assign'], $params['text']);
} else if(isset($params['assign']) && $params['assign'] != '' && $error) {
     $smarty->assign($params['assign'], '#');
} else if(!$error) {
     echo $seo_url;
} else if($error && $params['text'] != '') {
     echo $params['text'];
} else if($error) {
     echo '#';
}

adodb_connect();
the UDT requires a product ID and ideally some text, it connects to another DB and finds associated SEO URL and returns a link to that product, but more importantly, it sends an email when a product goes missing (disabled, deleted), in which case the UDT also returns plain text instead of a link. this way, the user is less likely to see that something is not quite right. BTW, i'd love to see a similar feature for links to disabled CMSMS pages (instead of a link to homepage).