Monday, July 2, 2012

GSoC 2012 - 6th Week Progress

     In last week I almost finish the implementing class behavior of PMA_CommonFunctions.class.php but not committed due to some conflicts while merging the code to with master branch.

         In this week also I got lots of conflicts while merging the code. Since the functions inside PMA_CommonFunctions class (in master common.lib.php file)  were used in many places over the PMA the possibility of occurring a conflict is high. With the merge of Alex's code I again got many conflicts. As well I had to do more modifications because Alex has introduced several new files and they have used the functions in common.lib.php . After did those modifications I committed the code with 4 known issues in master. At the moment two are already fixed in master branch. Others are,

1. When the session expires, after click logout I get following notice,
Notice in ./libraries/relation.lib.php#35
Undefined index: controllink

2. When incorrect login, following warning raised, 
Warning in ./libraries/dbi/mysqli.dbi.lib.php#97
mysqli_real_connect(): (28000/1045): Access denied for user 'root'@'localhost' (using password: YES)

         After that I moved into finding the possibility of using PMA_mimeDefaultFunction() function which is currently inside the core.lib.php file as a global function, inside the PMA_DisplayaResults class. This function is only used by the functions in PMA_DisplayResults class indirectly with the help of a variable. I moved the PMA_mimeDefaultFunction() function from core.lib.php file to PMA_DisplayResults class and renamed as _mimeDefaultFunction(). The places where calls this function indirectly were modified by adding '$this->' suffix ($default_function = '_mimeDefaultFunction'; $this->$default_function()).

          After those improvements I moved into implement tests for the functions in PMA_DisplayResults class. Yasitha has already implemented some tests for some functions. I started to continue that work and finished some tests.

         In next week as the major task I'm intending to implement tests for remaining functions in PMA_DisplayResults class. If possible I'll be do some minor improvements in PMA_CommonFunction.class.php








Monday, June 25, 2012

GSoC 2012 - 5th Week Progress

      This is the 5th week of my GSoC 2012 project. In last week I started to implement class behavior in common.lib.php file.

       This week I finish remaining part of the implementing class behavior in common.lib.php file. Now the class is named as PMA_CommonFunctions and file is appeared as CommonFunctions.class.php. This class is used singleton pattern to avoid the creation of many objects by several places, which needs more memory. If any function or file with procedural codes contain more than one function inside PMA_CommonFunctions class the class object is assigned to a variable called $common_functions and used that variable to call needed functions inside that class. The classes which use the functions in PMA_CommonFunctions class, were modified by adding getter setter methods to get/set PMA_CommonFunctions class object.

                  I faced several problems while implementing this part. Some functions were used more than 400 times in many files. All of those cannot be just replaced due to some JS functions also appeared with same name. After completing those modifications, I could only see login screen on my browser. After login nothing displayed in my browser. Then according to guidance of Michal, I enabled write error log to file. So that I could debug the code. Then I found that the error was due to calling non-static methods in side static functions in some classes. Those were replaced by direct calling using the static method (PMA_CommonFunctions::getInstance()->someFunction()) instead of get the use of variable for store class instance.

       Then the code was seems work fine. At the moment code is not committed yet due to some conflicts while merging the original PMA code. I'll be able to commit those changes as soon as after resolving them.

            In next week I'll start to looking at the possibility of using PMA_mimeDefaultFunction() function (at the moment this is inside core.lib.php file) inside PMA_DisplayResults class as suggested by Marc. If possible unit tests were implement for the functions inside PMA_DisplayResults class.

Monday, June 18, 2012

GSoC 2012 - 4th Week Progress

      In my third week I introduce a class behavior for display_tbl.lib.php file. Now that file has appeared as DisplayResults.class.php and the class inside it is named as PMA_DisplayResults.

              Since there was a task not completed in last week, I first completed that. It is removing imported super globals from the functions. There were several functions which used local variables which are imported from $GLOBALS super global array. I removed them and directly used super globals where needed. As well for the super globals which were not change during one execution cycle of the PMA code, I assign them to global variables in the PMA_DisplayResults class (local for that class). That global variables are initialized inside constructor.

         As next task, I was moved into fix the bug which was occurred due to breaking _getTableBody() function into subfunctions. It was very helpful for me that Marc had already mentioned the bug is about breaking the feature, which display a link for foreign table value. When I going through the code I saw that was occurred due to incorrect method calling of _getDataCellForNumericFeilds() function (not according to the signature). Now the bug is fixed.

            Then I moved into refactoring common.lib.php file. First I remove the HTML renderings inside the function it selves and return a string instead of that. As well some conventions are used according to my proposal. And the all functions names were modified by removing phrase 'PMA_'.

            Within next week I'm intending to complete implementing class behavior of common.lib.php file. While refactoring DisplayResults.class.php file I have moved a function (PMA_mimeDefaultFunction) to common.lib.php file and now again move it to core.lib.php file for keep it as global function. I intend to again look at the possibility of get that function back to DisplayResults.class.php file.

Tuesday, June 12, 2012

GSoC 2012 - 3rd Week Progress

In my 2nd week, I did some improvements relating to readability and usability of the code including breaking large functions into sub functions. After that step, display_tbl.lib.php file contained many sub functions.

In this week, I mainly focused on applying class behavior to the display_tbl.lib.php file. After getting the confirmation from Michal Čihař for the rough design of that PMA_DisplayResults class, I started my work.

First I search for the functions which are used by the outsiders. There were only two functions (PMA_getTable(), PMA_setConfigParamsForDisplayTable()) were used by sql.php file. Excepting those two functions, private key word was used as access modifier for all other existed functions. For constructor and the above two functions were appeared as public so that any outsider can access those. All existed function names were modified by removing 'PMA_' since they becomes to local functions. The file display_tbl.lib.php was renamed as DisplayResults.class.php .

Then I looked into, remove strings used for conditions in comparisons and introduce constants instead of that. There were many constants after doing this step. If there is any need for change the value of those strings, we can do it by just changing in one place. That is an advantage of using constant.

With these processes there were lots of code violations had been occurred. Most of them were fixed excluding some warnings which were due to very long comparisons inside if conditions.

Introducing global variables for the PMA_DisplayResults class is not finished yet. It will be done in next week. Unexpectedly there was a bug due to one of my previous commits which was pointed by Marc Densile. I am going to fix it in the next week. As well, I'll start to look into refactoring other files related to display query results. Mainly I'll focus on common.lib.php file.

Tuesday, May 22, 2012

Design for the PMA_DisplayResults class of PMA

PMA_DisplayResults class will contain the functions specific to the displaying query results and handling special tables like `PROCESSLIST` which provides informations on current threads running in PMA. At the current code base, these functions are appeared as global functions inside display_tbl.lib.php file. After introducing PMA_DisplayResults class instead of this set of functions, the file will be renamed as DisplayResults.class.php .

Class diagram (not the completed one) for the PMA_DisplayResults class


Following code snippet represent some rough implementation of the PMA_DisplayResults class,
class PMA_DisplayResults {
    
    const DIRECTION_LEFT = 'left';
    const DIRECTION_VERTICAL = 'vertical';
    
    private $_db;
    private $_table;
    
    public function __construct($db, $table) {
        $this->_db = $db;
        $this->_table = $table;
    }
    
    public function getTable() {
        
        // Related code for getTable function
        $str .= $this->_getTableHeaders();
        // end of the related code
        
    }
    
    private function _getTableHeaders() {
        //code...
        $msg = PMA_getMessage($this->_db, $this->_table);
        //code...
    }
    
}


As the only outsider accessed Display class, the sql.php file will be use,
// inside sql.php file
$displayResultsObj = new PMA_DisplayResults($GLOBALS['db'], $GLOBALS['table']);
echo $displayResultsObj->getTable();


GSoC 2012 - 2nd Week Progress

       This is my second week of GSoC 2012 project since I have started my coding before the official day. I have started to refactoring the file display_tbl.lib.php in PMA. Last week I remove the HTML rendering inside the functions it selves in this file. Some readability improvements also done.

         In this week, I mainly focused on improving the readability of the code inside display_tbl.lib.php file. There were several function which having more than 200 code lines in this file. I broke those functions into sub functions in a way that each sub function do a specific portion for the bigger function. As well the sub functions were not having very large code blocks and those functions were placed just after the referring function.  The names of these sub functions were little longer sometimes, because of they express valuable details for the developer at the first time.

                 In some places there were used similar code segments again and again even in the same functions. Those similar code segments were moved into new sub functions with the help of some additional parameters to separate out the small differences. (PMA_getOperationLinksForVerticleTable, PMA_getColumnParams etc.)

I have mentioned those larger functions which were broken into sub functions with there names below.

  • PMA_getTableNavigation
    • PMA_getMoveBackwardButtonsForTableNavigation
    • PMA_getShowAllButtonForTableNavigation
    • PMA_getMoveFarwardButtonsForTableNavigation
    • PMA_getAdditionalFieldsForTableNavigation
  • PMA_getTableHeaders
    • PMA_getSortByKeyDropDown
    • PMA_getDataForResettingColumnOrder
    • PMA_getOptionsBlock
    • PMA_getFullOrPartialTextButtonOrLink
    • PMA_getFormForMultiRowOperations
    • PMA_getCommentForRow
    • PMA_isInSorted
    • PMA_getSortingUrlParams
    • PMA_getSortOrderLink
    • PMA_getDraggableClassForSortableColumns
    • PMA_getDraggableClassForNonSortableColumns
  • PMA_getTableBody
    • PMA_getUrlSqlQuery
    • PMA_getColumnParams
    • PMA_getVerticalDisplaySupportSegments
    • PMA_getModifiedLinks
    • PMA_getDeleteAndKillLinks
    • PMA_getPlacedLinks
    • PMA_getResettedClassForInlineEdit
    • PMA_getClassForDateTimeRelatedFields
    • PMA_getDataCellForNumericFeilds
    • PMA_getDataCellForBlobField
    • PMA_getDataCellForGeometryFields
    • PMA_getDataCellForNonNumericAndNonBlobFields
  • PMA_getVerticalTable
    • PMA_getOperationLinksForVerticleTable
    • PMA_getCheckBoxesForMultipleRowOperations
  • PMA_getTable
    • PMA_getOffsets
    • PMA_getSortParams
    • PMA_getSortedColumnMessage
    • PMA_setMessageInformation
    • PMA_getMultiRowOperationLinks

         Apart from this I used some coding conventions for improve the readability. If the function is not too small one, an empty space were kept both after starting bracket of the scope and before ending bracket of the scope. Not only for that, wherever I saw the codes are seems packed and hard to read, I put empty lines between code segments. As well I followed the conventions suggested in my proposal.

                     At next week, I'm going to change my plans by giving the place to most prioritized task at the moment. I am going to make the display_tbl.lib.php file as a PHP class. As well I'm going to reduce the usage of global variables which are used in most of the functions. The strings used inside the functions for comparisons, will be replaced with constants. The design for the class will be discussed with the community on next week.

Monday, May 14, 2012

GSoC 2012 - 1st Week Progress

                            This is my first week of Google Summer of Code project which is Refactoring: Displaying query results under phpMyAdmin organization. Since I have my final examination, I started my work before the official day for start coding(21st May). It was a great experience that working with world wide open source community. That experience will be very helpful for me to manage my work in the upcoming weeks.

       According to my project schedule, I was dealing with, refactoring the file "display_tbl.lib.php" in this week. That is a file with 22 global functions. Some of them are really huge functions. As well, though library files are suppose to provide functions which having logics(calculations, concatenation, manipulation etc), while being in a separate layer (data/model layer), this file have some HTML renderings inside themselves. And the naming convention of some methods were different from the phpMyAdmin (PMA) standards.

           In this week, I modified the all the needed functions in "display_tbl.lib.php" file, to remove the HTML renderings inside themselves. Instead of that, that functions are now returning a string which having relevant HTML content for each function. Since inside some of functions are using the functions in "common.lib.php" file and some of them also had the same issue, I modified them as well. The unit tests for each also modified according to the changes I did in corresponding functions.

            The names of most of the functions were changed due to changing of the behavior of some functions. Those names were changed with adding "get" phrase. I was also looked in to modify the code to keep necessary indentation, since it improve the readability of the code.

         At next week, I'll more look into improve the readability of the code with adding the suggested conventions in my proposal. As well the huge functions will be braked in to several functions. The unit tests also will introduced as possible for those function.