How to access DboSource from shell

2010-08-21 Thread dmc
I have to to set DboSource::$cacheMethods to false (http://
api13.cakephp.org/view_source/dbo-source/#line-64).
Tried it this (and many other) way(s).
But apparently it does not work.
I really need to disable this caching but only for this shell.

?php
class MyShell extends Shell
{
var $uses = array(...);

function initialize()
{
App::import(ConnectionManager);
$db =ConnectionManager::getDataSource('local');
$db-cacheMethods = false;
parent::initialize();
}


function main()
{

}



I also tried the same in the startup- and in the main-function.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: One for the experts: Cake mixing up SQL-queries

2010-08-20 Thread dmc
thank you very much.
that sounds very promising.

Is it possible to set dboSource::cacheMethods to false from within a
controller/shell-script?
Or do I have to do this in the config or (even worse) only inside
dbosource.php?

I wouldn't want to switch it off application-wide.
Just for the one shell-application would be the best.



On 19 Aug., 19:00, AD7six andydawso...@gmail.com wrote:
 On Aug 19, 3:57 pm, dmc daniel.mitsc...@gmail.com wrote:

  Nobody any idea?

 investigate if the crc32 hash used in dbo_source.php is the same for
 your desired query and the one it's being confused with. If it is the
 cause (which with so many queries, and crc32 hashing, it's quite
 likely) just disable this query cache on the db source.

 Otherwise you need to find a means of a reproducible error that
 doesn't take you 5 hours to trigger.

 AD

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: One for the experts: Cake mixing up SQL-queries

2010-08-20 Thread dmc
Ok, gave it a try this way.
Will have to wait for the next import tonight.

class importShopdataShell extends Shell
{
var $uses =
array(VsShop,VsArticle,VsCategory,VsMake,VsArticleHasVsCategory,'VsLog',VsArticleTest,VsArticleHasVsCategoryTest,AdminUser);
var $tasks = array('Email');
var $Email;

function main()
{
set_time_limit(0);
ini_set('memory_limit', '512M');
ini_set(error_reporting, E_ALL);
ini_set(log_errors, 1);
if(ENVIRONMENT != localhost)
{
ini_set(error_log, /var/log/php/live.log);
$db = ConnectionManager::getDataSource('live');
}
else
{
$db = ConnectionManager::getDataSource('local');
}
$db-cacheMethods = false;


Or is there any other way?


thanks

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: One for the experts: Cake mixing up SQL-queries

2010-08-19 Thread dmc

Nobody any idea?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


One for the experts: Cake mixing up SQL-queries

2010-08-17 Thread dmc
Hi,

I'm letting Cake (Version 1.3.3) do some automatic imports over night
and it's doing the same thing for about half a million times.
It's working pretty well but every night I get some (about 10) really
weird SQL-errors.
I just don't understand how these even can occur.
It seems that cake is mixing up conditions from different queries
sometimes and even misspelling model-names.

This is the function that is doing the SQL-queries:

function __saveArticle($product, $hashkey, $shopId)
{
$this-VsArticle-create();
$this-VsArticle-id = false;
$this-data[VsArticle] = $product;

$this-VsArticle-recursive = -1;
$existingArticle = $this-VsArticle-find('all', array(limit = 1,
fields = array(VsArticle.id,VsArticle.toparticle), 'conditions'
= array(
'VsArticle.artnr' = $this-data[VsArticle][artnr],
'VsArticle.vs_shop_id' = $shopId)));

if(!empty($existingArticle))
{
$this-VsArticle-id = $existingArticle[0][VsArticle][id];
$this-updateCount++;
}
else
{
$this-data[VsArticle][status] = imported;
$this-data[VsArticle][vs_shop_id] = $shopId;
$this-newCount++;
}

if($existingArticle !== false)
{
if($this-VsArticle-save($this-data))
{
$lastArticleId = $this-VsArticle-id;
$this-VsArticleHasVsCategory-deleteAll(vs_article_id 
=
$lastArticleId, false);

foreach($this-data[VsArticle][categoriesIds] as 
$categoryId)
{
$this-VsArticleHasVsCategory-create();

$this-data[VsArticleHasVsCategory][vs_article_id] =
$lastArticleId;

$this-data[VsArticleHasVsCategory][vs_category_id] =
$categoryId;

$this-data[VsArticleHasVsCategory][vs_shop_id] = $shopId;
$this-data[VsArticleHasVsCategory][hash] = 
$hashkey;

$this-VsArticleHasVsCategory-save($this-data);
}
}
}

}


And here are some of the errors (with the corresponding SQL-Query):

[14-Aug-2010 01:58:35] PHP Warning: SQL Error: 1054: Unknown column
'vs_articles.id' in 'where clause' in /var/cakephp/cake/libs/model/
datasources/dbo_source.php on line 682
[14-Aug-2010 01:58:35] SQL ERROR: SELECT `VsArticle`.`id`,
`VsArticle`.`toparticle` FROM `vs_articles` AS `VsArticle` WHERE
`vs_articles`.`id` = 12040 ORDER BY `VsArticle`.`title` ASC LIMIT 1

[14-Aug-2010 04:48:20] PHP Warning: SQL Error: 1054: Unknown column
'VsArticle.artnr' in 'where clause' in /var/cakephp/cake/libs/model/
datasources/dbo_source.php on line 682
[14-Aug-2010 04:48:20] SQL ERROR: DELETE FROM `vs_articles` WHERE
`VsArticle`.`artnr` = '441124' AND `VsArticle`.`vs_shop_id` = 120

[15-Aug-2010 04:15:27] PHP Warning: SQL Error: 1054: Unknown column
'VsArticle.artnr' in 'where clause' in /var/cakephp/cake/libs/model/
datasources/dbo_source.php on line 682
[15-Aug-2010 04:15:27] SQL ERROR: DELETE `VsArticleHasVsCategory` FROM
`vs_article_has_vs_category` AS `VsArticleHasVsCategory` WHERE
`VsArticle`.`artnr` = '51715236-2-6-3-38-242' AND
`VsArticle`.`vs_shop_id` = 141

I know, it's not easy to understand, but please have a look at the
last error I posted.
As you can easily see, it's mixing up to queries:

   existingArticle = $this-VsArticle-find('all', array(limit
= 1, fields = array(VsArticle.id,VsArticle.toparticle),
'conditions' = array(
'VsArticle.artnr' = $this-data[VsArticle][artnr],
'VsArticle.vs_shop_id' = $shopId)));
AND
   $this-VsArticleHasVsCategory-deleteAll(vs_article_id =
$lastArticleId, false);

So somewhere in the cake-core the SQL-querybuilding get's pretty much
mixed up.
I just don't know what could trigger this and where exactly it
happens.
Not easy to debug, as this import is running for about six hours.

Does anybody have ANY idea what could cause this odd behavior?


best,

d.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: One for the experts: Cake mixing up SQL-queries

2010-08-17 Thread dmc
These are the Models and the corresponding SQL-Structure:

class VsArticle extends AppModel {

var $name = 'VsArticle';

var $actsAs = array(Containable);

var $displayField = title;
var $order = VsArticle.title;

var $belongsTo = array(VsShop = array(exclusive = true),
VsMake = array(exclusive = true));
var $hasAndBelongsToMany = array(VsCategory = array(
className = VsCategory,
joinTable = vs_article_has_vs_category,
unique = true,
exclusive = true
));
}

id  bigint(20)
status  varchar(45)
artnr   varchar(255)
title   varchar(255)
price   float
img_url varchar(1024)
imglarge_urlvarchar(1024)
deeplinkvarchar(1024)
descr   text
descr_short text
gender  int(11)
created datetime
modifieddatetime
vs_make_id  int(11)
vs_shop_id  int(11)
original_category   varchar(255)
original_make   varchar(255)




class VsArticleHasVsCategory extends AppModel {
var $name = 'VsArticleHasVsCategory';
var $useTable = vs_article_has_vs_category;
}

id  bigint(20)
vs_article_id   bigint(20)
vs_category_id  int(11)
vs_shop_id  int(11)
hashvarchar(255)




Did you see the mixed up Query?

DELETE `VsArticleHasVsCategory` FROM
`vs_article_has_vs_category` AS `VsArticleHasVsCategory` WHERE
`VsArticle`.`artnr` = '51715236-2-6-3-38-242' AND
`VsArticle`.`vs_shop_id` = 141

The whole query makes no sense at all: it is deleting from the Table/
Model VsArticleHasVsCategory (which is correct) but is referring to
the Table/Model VsArticle in the WHERE-statement.
And the WHERE-statement corresponds to the first model-find-statement
in the function:

'conditions' = array(
'VsArticle.artnr' = $this-data[VsArticle]
[artnr],
'VsArticle.vs_shop_id' = $shopId
)


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Accessing my returned value from model function

2008-01-20 Thread dmc

i am trying to show a returned value from a model
function.
function shoWonum()
{
$ret = $this-query(SELECT wonum FROM invoices WHERE id =
3);
$wonum = $ret[0]['wonum'];
return $wonum;
 }

(this SQL stement returns '1' as the returned value - btw)

in my controller i access the function by:


$this-set('baseWonum', $this-Invoice-shoWonum());


in my view i have the value:

$baseWonum - but it is always empty

I am very new to the frame work and am sure i am making a basic
mistake
any help would be greatly appreciated - thank you all



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---