The OOP & refactor project weekly report 11

During the last Wednesday to now I fixed some bugs on the new StrucutureController, and start thinking of refactoring the Import/Export module.

Files Covered In This Week

  • libraries/controllers/StructureController.class
  • db_structure.php
  • tbl_structure.php

Outcomes In This Week

Fix bugs appeared in the StructureController
While testing on the StructureController, we had found some bugs that cause some functions doesn’t work properly (bulk delete, etc). After tracing the execution of the code, I found that the the scripts we directly included/required use some global variables that are not available in that context. So most problems solved after adding global declaration to them. In addition, in the future I suggest we should remove these scripts by creating individual functions for them.

What Will I Do Next

Due to the import/export module is hard to decompose and derive controllers, we decided working on recovering test coverage first.

Advertisements
The OOP & refactor project weekly report 11

The OOP & refactor project weekly report 10

During the last week I refactored the structure.lib.php by creating the StructureController. So far, the controller was created and the display_structure.inc.php remains being analysed.

Files Covered In This Week

  • libraries/controllers/StructureController.class.php
  • libraries/structure.lib.php
  • db_structure.php
  • tbl_structure.php
  • templates/structure

Outcomes In This Week

Create the StructureController
First I created templates for the PMA_getHtml series functions. After that, we decided to create a controller for the structure handle logics, therefore I created the StructureController. Functions that involved in the strucuture.lib.php will be moved into the controller. Some functions still require $db and $table parameter at this moment since the controller is in its initial phase. I will update the PR with optimisations and removal of the redundant parameters.

Move some functions to PMA_Table
Some functions like getColumnsWithIndex and getRealRowCountTable should be categorised as the table related functions, so it should be moved into the PMA_Table class.

What Will I Do Next

First I will finish creating and testing the StructureController, then I will start working on the Import/Export module.

The OOP & refactor project weekly report 10

The OOP & refactor project weekly report 9

Hello everyone, during last week I almost finished my work on the TableSearch class and the Table class. A TableSearchController was created for handling table searching operations such as zoom search and replacing search. But unfortunately there still some test failures, I will comment it out and fix it later. Also, I must deeply apologise for lateness in respond to the community during last week.

Files Covered In This Week

  • libraries/controllers/TableSearchController.class.php
  • libraries/Table.class.php
  • libraries/TableSearch.class.php
  • tbl_find_replace.php
  • tbl_select.php
  • tbl_zoom_select.php

Outcomes In This Week

Create the TableSearchController
After analysing the PMA_TableSearch class, we decided to create a controller to handle requests for the search function of tables. I applied similar strategies used on controllers before for tbl_select.php, tbl_zoom_select.php and tbl_replace.php.

Change some member functions in PMA_Table class to non-static
Some static member functions in PMA_Table class like isView() and isMerge() is highly related with specific tables, so it should be associated with an instance of the PMA_Table class. Therefore I made them non-static.

Fix test failures in PMA_Table_test
Test failures came as I converted some member functions to the non-static version. I believe the problem is caused by fault in creating stubs for test, but I can’t still fix it yet since the lack of knowledge on mocking objects in phpunit. If I still cannot fix the test problem before 10:00 am, July 21st 2015, I may comment the tests out first and work on it again after I finish creating templates for structure.lib.php.

What Will I Do Next

I started working on refactoring structure.lib.php. A new PR was opened, and according to the timeline submitted before, I should get it done before July 25th 2015.

The OOP & refactor project weekly report 9

The OOP & refactor project weekly report 8

Hello, during last week I majorly spent time on the TableSearch class. In the same time, I also tested and fixed problems in the TableGisVisualizationController.

Files Covered In This Week

  • libraries/controllers/TableGisVisualizationController.class.php
  • libraries/Table.class.php

Outcomes In This Week

Test & Fix on TableGisVisualizationController
Thanks to the community’s help, finally I can test my works on the TableGisVisualizationController. By using GIS data provided in phpMyAdmin official demo, I found a problem in loading the GisVisualization class too early.

About the Table class
To convert the Table class into a completely OOPed one, we must first achieve encapsulation on it. First I moved the PMA_Table::cache to PMA_DatabaseInterface class, and provide some functions to manipulate it.

What Will I Do Next

In the following week, I will finish working on Table class and TableSearch class. I will refactor the TableSearch class to TableSearchController as my mentor suggested.

The OOP & refactor project weekly report 8

The OOP & refactor project weekly report 7

During the last week I finished my work on the dependency injection container and a helper for the template system. Also, the mid-term evaluation was submitted. I am grateful of being one of the PMA developers 🙂

Files Covered In This Week

  • libraries/ArrayHelper.class.php
  • libraries/tbl_columns_definition_form.inc.php
  • libraries/di/*

Outcomes In This Week

The helper for template system & Refactor tbl_columns_definition_form.inc.php
In order to refactor tbl_columns_definition_form.inc.php, I created this helper to simplify branching and accessing array elements. By using PMA\Util\get, it enable us access an array using dot notation. Here is an example:


require_once 'libraries/util.lib.php';
use PMA\Util;
$test = array('a' => array('b' => array('c')));
echo Util\get($test, 'a.b');

It will print the result below:

c

If the specified path or the value not exist, it will return a default value. The default value can be set as the third parameter of the function. It’s set to null by default.

Dependency Injection Container
First I implemented the container using closures, but phpunit failed so that I can only implement a new one in class form. The dependency container is mainly use to free us from passing plenty of parameters to construct classes.

When we use the container, we can just set up some global parameters like $GLOBAL['dbi'] and $GLOBAL['url_query'] in it. We can also register services or factories (Container::factory and Container::service). After we finish setting up dependencies, we can construct the class by calling Container::get and pass the rest of user-specified parameters for the class. We don’t need to worry about the long-long parameter list, since the container will resolve by itself.

What Will I Do Next

In the following 1 weeks, I will work on refining the Table class and TableSearch class.

The OOP & refactor project weekly report 7

The OOP & refactor project weekly report 6

In this week I succeed in decomposing tbl_columns_definition.lib.php, and designed a structure for controller classes. Also, I have done some optimization on the GIS_Visualization.class.php. Now I am working to take logic-controlling codes out from table related scripts (tbl_*.php) to form table controllers.

Files Covered In This Week

  • tbl_columns_definition.lib.php (Decomposed)
  • GIS_Visualization.class.php
  • libraries/controllers

Outcomes In This Week

Decomposing tbl_columns_definition.lib.php
I have decomposed the PMA_getHtmlForColumnAttributes by taking its logic into a new template named “columns_definition/column_attributes”. In this template it handles the generation of $content_cells. Also, other functions that related to PMA_getHtmlForColumnAttributes was converted to templates.

Designing the Controller class
I’d like to introduce a general controller system for PMA, which was designed to handle most of logic in the program. The controller classes was designed with following structure:

Dependency Injection Container

The structure has multiple layers, in each layer it can provide some utility functions or variables that could be accessed in the lower layer. So far I created a Controller class as the base class for any other controllers and it provides $dbi and $response for general usages. And I’d like to create a $request object that helps handling $_REQUEST variable in the future of work.

Also, as the structure diagram shows, I’d like to have a dependency injection container in the future, but it’s likely to become too complex at this moment. So I’m considering whether we could have a better solution for dependency injection.

Last but not least, we should remember that the controllers should be put in libraries/controllers directory and PMA\Controllers namespace. I suggest that we should use namespaces and directories following PSR-4 rules in our future works.

The Problems We Are Facing

Test against the tbl_gis_visualization.php
Today I’ve converted the tbl_gis_visualization.php to the controller form I mentioned above. But I’m not so familiar with GIS data and I can’t find out how to test against the work. Any advice for that are welcomed.

Cleaning up messy structures
Some of codes in our code base is not so friendly 😦
We can see undefined variables (defined in somewhere we would never knows), codes that inline includes and $GLOBALS reference anywhere. We need a better way to clean up them, or it would slow down the refactor process.

A Template Helper
When I was working on tbl_definition_form.inc.php I found that it was directly include in many places. But I couldn’t create template this script because there are too much logic handling codes in it. I think we can create a template helper class only holds static helper functions so that we can easily create template for such kind of scripts.

What Will I Do Next

In this week I will finish constructing Table controllers. A commit with some new controllers will be available soon.

The OOP & refactor project weekly report 6

The OOP & refactor project weekly report 5

In this week I started the second phase of my work — OOPing table related scripts. I’d like to create a basic MVC structure for table related scripts. Before diving into the MVC structure, in this week I was decomposing tbl_*.lib.php for the convenience of the future work.

Files Covered In This Week

  • gis_data_editor.php
  • tbl_gis_visualization.php
  • GIS_Visualization.class.php
  • tbl_columns_definitions_form.lib.php
  • tbl_columns_definitions_form.inc.php
  • central_columns.lib.php
  • normalization.lib.php
  • Table.class.php
  • tbl_indexes.lib.php

Outcomes In This Week

The new GIS_Visualization class
First I found that the effect of the GIS_Visualization class is to convert raw data into diagrams and images. So I used Factory Pattern on it, and replace the constructor with a new private constructor. When we need to use this class, we can just use it in this way:

require_once 'libraries/gis/GIS_Visualization.class.php';
PMA_GIS_Visualization::get($sql_query, $options, $row, $pos, $data = null);

Notice: The $sql_query is the SQL using to fetch raw data from database, and the $row and $pos is the same as function PMA_GIS_modifyQuery($sql_query, $visualizationSettings, $rows = null, $pos = null) before. When we specify $data field in the constructor, other parameters except $options make no effect.

Some tbl_*.lib.php scripts decomposed
I am going to create a TableController to handle logic just I mentioned before, so I decomposed them and move these logics into corresponding tbl_*.php for convenience. Logic processing codes can be easily extracted from tbl_*.php when I started to create the TableController class with these logics represented as methods.

Somethings about the tbl_columns_definition_form.lib.php
Now there is only one functions PMA_getHtmlForColumnAttributes left in the tbl_columns_definition_form.lib.php. After I figure out ways to elimate it, I will create a new PR.

What Will I Do Next

Now I have almost finished decomposing tbl_*.lib.php scripts. In next few days I will create a TableController class for handling logic processing and communicate with the Table class to fetch data. The TableController class should available at June.18th.

The OOP & refactor project weekly report 5