[Vtigercrm-developers] getRecordOwnerId() in utils.php

Adam Heinz amh at metricwise.net
Wed Jan 23 13:50:16 PST 2013


Ah, right! The logic isn't looking for > 1, it's looking for < 1.  Thanks,
man.  Whenever I can't believe my eyes it is always good to ask for a
second opinion.


On Wed, Jan 23, 2013 at 4:45 PM, Joe Bordes <joe at tsolucio.com> wrote:

>  Hi Adam,
>
> I think the function is correct. Let me try to explain what I understand:
>
> In line 1309:
>
> $query="select smownerid from vtiger_crmentity where crmid = ?";
>
> We get the ownerid of the record passed in as a parameter, but we don't
> know if this ID belongs to a user or to a group.
>
> The next step is to make sure we got an ownerid:
>
> if($adb->num_rows($result) > 0)
>
> Ok, once inside this "if", we need to know if the ID we have is a user or
> a group, so we launch the SQL:
>
>
> $sql_result = $adb->pquery("select count(*) as count from vtiger_users
> where id = ?",array($ownerId));
>
> if the ownerid is of a user, this will return 1, if it belongs to a group
> it will return 0, thus the next "if" which fills the array (with only one
> ID always).
>
> So, I'm not sure what the stock functions is sending in, probably still
> the prior to 5.4.0 product handler instead of the new 5.4.0 assigned user,
> but I think the getRecordOwnerId() function is correct.
>
> Joe
> TSolucio
>
>
>
>
> On 23/01/13 21:24, Adam Heinz wrote:
>
> I'm mucking around with an aftersave handler for the Quotes module today
> and I started seeing some warnings getting logged.  It looks like the
> product stock email is causing them, but when I trace into the code [1] my
> jaw hit the floor.  Am I reading this right?  This function seems to think
> that you can get back more than one user for a given id, which is
> impossible, since id is the primary key for vtiger_users.  So then it
> passes the array('Users' => ID) to getOwnerName to getOwnerNameList and
> eventually blows up because it tries to use an array for an array key.  To
> keep the blast radius small, I patched around the error [2], but I think
> the moral of the story is that getRecordOwnerId() should be rewritten or
> removed and all uses of it changed.
>
>  [1]
> http://trac.vtiger.com/cgi-bin/trac.cgi/browser/vtigercrm/branches/5.4.0/include/utils/utils.php#L1303
> [2]
>  Index: include/utils/InventoryUtils.php
> ===================================================================
> --- include/utils/InventoryUtils.php (revision 3777)
> +++ include/utils/InventoryUtils.php (working copy)
> @@ -110,7 +110,7 @@
>   if($upd_qty < $reorderlevel)
>   {
>   //send mail to the handler
> - $handler = getRecordOwnerId($product_id);
> + $handler = $adb->database->GetOne("SELECT smownerid FROM
> vtiger_crmentity WHERE crmid = ?", array($product_id));
>   $handler_name = getOwnerName($handler);
>   if(vtws_isRecordOwnerUser($handler)) {
>   $to_address = getUserEmail($handler);
>
>
>
> _______________________________________________http://www.vtiger.com/
>
>
>
> _______________________________________________
> http://www.vtiger.com/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20130123/724e5755/attachment-0001.html 


More information about the vtigercrm-developers mailing list