Details
-
Type:
Bug
-
Status: Done/Fixed
-
Priority:
Blocker
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.7
-
Fix Version/s: 4.7.12
-
Component/s: CiviCampaign
-
Labels:
-
Documentation Required?:Developer Doc
-
Funding Source:Contributed Code
Description
Hello,
It's my first contribution, if someone thinks that it's fail or could to get better solution, please go ahead, i want help out.
Function Core System getPcpDashboardInfo
civicrm/CRM/PCP/BAO/PCP.php Line 116 to 124:
$query = "
SELECT * FROM civicrm_pcp pcp
LEFT JOIN civicrm_pcp_block block ON block.id = pcp.pcp_block_id
WHERE pcp.is_active = 1
AND pcp.contact_id = %1
ORDER BY page_type, page_id";
Now you can peek, this query is looking for PCP in database, and showing all tables of civicrm_pcp and civicrm_pcp_block, this include their "ID", it can be fail because depend the configuration of database server the result, i mean, the server will select between pcp_block's(table) ID or pcp's(table) ID(In my case, my database server, selected the block ID instead of PCP ID), it's bad because pcp(table) and pcp_block(table) they has the same ID field name, but, it's good structure schema in database, the problem is the query, and can be solve.
My Solution:
$query = "
SELECT pcp.*, block.is_tellfriend_enabled FROM civicrm_pcp pcp
LEFT JOIN civicrm_pcp_block block ON block.id = pcp.pcp_block_id
WHERE pcp.is_active = 1
AND pcp.contact_id = %1
ORDER BY page_type, page_id";
I seen, this query only use 1 field from civicrm_pcp_block, it is is_tellfriend_enabled(field), the best practice to use on SQL, is show only the fields that you will need, as i said before, it's could be better, but it's my first contribution, someone can improve it.
I hope this can help,
Regards.