Code accessing SQL data structure outside of class

Bug #611815 reported by XavierAntoviaque
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Humanity Project
Fix Released
Medium
Vlad Dragu

Bug Description

Cf for example get_play_data() in functions/func_general.php.

Changed in hackit:
status: New → Confirmed
importance: Undecided → Medium
assignee: nobody → Vlad Dragu (vlad-dragu)
milestone: none → alpha1.1
Revision history for this message
Vlad Dragu (vlad-dragu) wrote :

I’m not sure I understand this bug. I looked at the get_play_data function and all db requests are done through the database class. What exactly should I modify?

Changed in hackit:
status: Confirmed → Incomplete
Revision history for this message
XavierAntoviaque (xavier-antoviaque) wrote :

Yes - it's not about using the database class to pass the SQL request, it's about not using SQL requests about a given data type at all outside of the classes that define the data.

For example, you have added classes to handle sites as objects. Those classes can (and have to) make SQL request to read and update the relevant tables. However, if you start accessing the raw SQL data directly outside of the classes definition, you end up bypassing the "site" classes to access the information. Which leads to code duplication (if you change the SQL representation of the data, you end up having to change it everywhere, instead of just looking at the relevant classes).

Look at index.php for example; you access the values of the resulting site_list to get the URL of the sites without using a site object. This is very tempting because you have access to the rows from the SQL request, which is why this shouldn't be "directly" accessible outside of a relevant class.

                                                       foreach ($site_list as $key=>$value) {
                                                                if (strpos($value['site'],"/home/")===0)
                                                                {
                                                                ?>
                                                                        <a href="<?php echo WEB_PATH; ?>" ><?php echo _('Homebase'); ?></a>
                                                                <?php
                                                                }
                                                                else
                                                                {
                                                                ?>
                                                                        <a href="<?php echo hackit_rel_url($value['site']) ?>"

Changed in hackit:
status: Incomplete → Confirmed
Changed in hackit:
milestone: alpha1.1 → alpha1.2
Revision history for this message
Vlad Dragu (vlad-dragu) wrote :

We are going to schedule the refactoring of the code with data objects starting with alpha 1.3. Correct?

Changed in hackit:
status: Confirmed → Incomplete
Revision history for this message
XavierAntoviaque (xavier-antoviaque) wrote :

Correct - actually alpha1.3 will be alpha2.0 : )

Changed in hackit:
milestone: alpha1.2 → alpha2
status: Incomplete → Confirmed
Changed in hackit:
milestone: alpha2.0 → none
Revision history for this message
XavierAntoviaque (xavier-antoviaque) wrote :

Why have you removed the milestone on this David?

Revision history for this message
david blanchard (david-blanchard) wrote :

I followed Vlad's comment on his mail (http://community.hackit.cx/forum/index.php?t=msg&th=4775&goto=9716&#msg_9716)

'For 611815 (implementing data objects) we didn’t schedule when we will start implementing it'

You hadn't agreed to this on your side ?

Revision history for this message
XavierAntoviaque (xavier-antoviaque) wrote :

Just saw the email - I replied there. Probably just a misunderstanding : )

Changed in hackit:
milestone: none → alpha2.2
Changed in hackit:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.