source: trunk/docs/codebase_v1-to-v2_upgrade_checklist.txt

Last change on this file was 468, checked in by anonymous, 10 years ago

Completed integrating /branches/eli_branch into /trunk. Changes include:

  • Removed closing ?> from end of files
  • Upgrade old-style contructor methods to use construct() instead.
  • Class properties and methods defined as public, private, static or protected
  • Ensure code runs under E_ALL with only mysql_* deprecated warnings
  • Search for the '@' symbol anywhere it might be used to supress runtime errors, then replace with proper error recovery.
  • Run the php cli -l option to check files for syntax errors.
  • Bring tests up-to-date with latest version and methods of PHPUnit
File size: 10.8 KB
Line 
1=====================================================================
2In General
3=====================================================================
4
51. Include methods have changed. Instead of accessing file paths absolutely, all files are searched in the include_path. So, instead of:
6
7    include SITE_BASE . '/_templates/header.ihtml';
8
9do this:
10
11    include 'header.ihtml';
12
13
142. CODE_BASE is a defunct constant. The location of the codebase is no longer important as long as it can be found in the currently configured include_path. This will usually include the local site directory (where the codebase normally would be found) as well as the server-wide /usr/lib/php directory where the codebase might be included for the whole server. So now, instead of this:
15
16    require_once CODE_BASE . '/lib/Utilities.inc.php';
17
18do this:
19
20    require_once 'codebase/lib/Utilities.inc.php';
21
22
233. $CFG-> variables are gone. Most of these should be converted into their $app and $auth equivalents. If a $CFG variable is NOT something used by the codebase but is still needed by the website application, I suggest converting these values to a $cfg array. For example, this:
24
25    $CFG->gallery_images_url = '/gallery_images';
26
27should become:
28
29    $cfg['gallery_images_url'] = '/gallery_images';
30
31And of course change the code where they are used to support the array instead of object-properties. If the array is inside of double-quotes it should be written like:
32
33    "{$cfg['gallery_images_url']}/my/path".
34
35If the value used is now to be retrieved from a $object->getParam(...) method call, you'll need to do this:
36
37    $object->getParam('gallery_images_url') . '/my/path'
38
39
404. $CFG->site_url is not needed when referencing URLs. Change this:
41
42    <a href="<?php echo ohref("$CFG->site_url/my/file.php"); ?>">
43
44to this:
45
46    <a href="<?php echo $app->ohref("/my/file.php"); ?>">
47
48(In other words, the URL should be a not-fully-qualified URL starting with a slash.)
49
50
51// 5. Expect formatting inconsistencies! When doing global search-replace expect whitespace to be erratic, variable names to change, and lines to be otherwise inconsistent. Here's a good example of a safe way to match a line:
52
53Searching for "$CFG->ssl_domain = 'www.example.com';":
54
55//    $CFG->(\w+)\s*=\s*['"](\w+)['"];
56
57Replace:
58
59    $app->setParam(array(
60        '\1' => '\2'
61    ));
62
63
646. Many classes now require object-method calls, and the object must be globally scoped. For example, to call the $cache->exists() method inside a function, be sure to add:
65
66    global $cache;
67
68at the top of the function.
69
70
71
72=====================================================================
73App
74=====================================================================
75
76The _config.inc.php file is 99% different. Start over from scratch using codebase/docs/example_config.inc.php.
77
78---------------------------------------------------------------------
79$CFG global variables are converted to object properties specific to their usage.
80
81For example:
82
83    $CFG->ssl_domain = 'www.example.com';
84    $CFG->login_timeout = 21600;
85
86are converted to:
87
88    $app->setParam(array(
89        'ssl_domain' => 'www.example.com'
90    ));
91    $auth->setParam(array(
92        'login_timeout'     => 21600,
93    ));
94
95---------------------------------------------------------------------
96Convert functions to methods.
97
98raiseMsg(...)                           $app->raiseMsg(...)
99logMsg(...)                             $app->logMsg(...)
100include 'message_header.ihtml';         $app->printRaisedMessages();
101$carry_queries = array(... , ...);      $app->carryQuery(...);  //call for each value in array
102ohref(...)                              $app->ohref(...)
103printHiddenSession(...);                $app->printHiddenSession(...);
104dieURL(...);                            $app->dieURL(...);
105dieBoomerangURL(...);                   $app->dieBoomerangURL(...);
106setBoomerangURL(...);                   $app->setBoomerangURL(...);
107getBoomerangURL(...);                   $app->getBoomerangURL(...);
108validBoomerangURL(...);                 $app->validBoomerangURL(...);
109deleteBoomerangURL(...);                $app->deleteBoomerangURL(...);
110sslOn();                                $app->sslOn();
111sslOff();                               $app->sslOff();
112
113The following regex will find any of the above:
114(?<!raiseMsg|logMsg|include|ohref|printHiddenSession|dieURL|dieBoomerangURL|setBoomerangURL|getBoomerangURL|validBoomerangURL|deleteBoomerangURL|sslOn|sslOff)
115
116Also convert all site config variables, as earlier:
117$CFG->site_name                         $app->getParam('site_name')
118
119=====================================================================
120DB
121=====================================================================
122
123dbQuery(...)                            $db->query(...)
124dbTableExists(...)                      $db->tableExists(...)
125addslashes(...)                         $db->escapeString(...)
126
127$dbh
128$GLOBALS['dbh']                         $db->getDBH()
129
130=====================================================================
131Auth_SQL
132=====================================================================
133
134$auth->clearAuth()                      $auth->clear()
135$auth->setVal(...)                      $auth->set(...)
136$auth->getVal(...)                      $auth->get(...)
137$auth->setFeature(...)                  $auth->setParam(...)
138$auth->getFeature(...)                  $auth->getParam(...)
139
140
141=====================================================================
142ImageThumb
143=====================================================================
144
145$thumb->setSourceDirectory(...)         $thumb->setParam(array('source_dir' => ...))
146$thumb->createDestDirs(...)             $this->_createDestDirs(...) NOW PRIVATE!
147$thumb->validFileExtension(...)         $this->_validFileExtension(...) NOW PRIVATE!
148
149=====================================================================
150MySQLSessionHandler
151=====================================================================
152
153Renamed to DBSessionHandler.inc.php
154Interface totally changed. See example in App.inc.php.
155
156=====================================================================
157Navigation
158=====================================================================
159
160Renamed to Navigation.inc.php
161
162$nav->addPage(...)                      $nav->add(...)
163$nav->setFeature(array(...))            $nav->setParam(...)
164$nav->getFeature(...)                   $nav->getParam(...)
165$nav->getTitle()                        $nav->get('title')
166$nav->printTitle()                      echo $nav->get('title')
167$nav->getPath()                         $nav->get('path')
168$nav->printPath()                       echo $nav->get('path')
169$nav->printBreadcrumbs()                echo $nav->getBreadcrumbs()
170
171$nav->path_delimiter                    $nav->getParam('path_delimiter')
172NOTE: this applies to any object property that has been converted to a param.
173
174
175=====================================================================
176PEdit
177=====================================================================
178
179Massive changes. See Quinn.
180
181=====================================================================
182Prefs
183=====================================================================
184
185$prefs = new Prefs($dbh, $params)       $prefs = new Prefs('namespace')
186NOTE: new instantiation interface
187
188$prefs->setDefault(..., scope)                 $prefs->setDefaults(array(...))
189NOTE: plurality - function need not be called once-per-default.
190
191$prefs->setValue(..., $scope)           $prefs->set(...)
192$prefs->getValue(..., $scope)           $prefs->get(...)
193$prefs->clearValue(..., $scope)         $prefs->delete(...)
194NOTE: $scope no longer used in the above methods.
195
196$prefs->retrieve()                      $prefs->load()
197
198=====================================================================
199Lock
200=====================================================================
201
202Renamed from RecordLock.inc.php to Lock.inc.php
203
204Only one major interface change: instead of calling $lock->dieErrorPage() you will wrap the header/footer includes around the method call $lock->printErrorHTML().
205
206Also, change instantiation call from:
207
208    $lock = new RecordLock($GLOBALS['_admin']);
209
210to:
211
212    global $lock;
213    global $auth;
214    $lock =& Lock::getInstance($auth);
215
216And instantiate the original global $lock object in _config.inc.php as follows:
217
218    // Global record-locking object.
219    $lock =& Lock::getInstance($auth);
220    $lock->setParam(array(
221        'timeout' => 0,
222        'auto_timeout' => 1800,
223        'error_url' => '/lock.php',
224    ));
225
226
227=====================================================================
228Version
229=====================================================================
230
231Renamed from RecordVersion.inc.php to Version.inc.php
232
233Change usage from:
234
235    $version = new RecordVersion();
236
237to:
238
239    $version =& Version::getInstance($auth);
240
241
242=====================================================================
243Cache
244=====================================================================
245
246Renamed from SessionCache.inc.php to Cache.inc.php
247
248Changed all method calls to now require object calls rather than static calls. In other words, change this:
249
250    if (SessionCache::isCached('mydata')) {
251        $list = SessionCache::getCache('mydata');
252    }
253
254to:
255
256    if ($cache->exists('mydata')) {
257        $list = $cache->get('mydata');
258    }
259
260And have $cache instantiated in _config.inc.php like this:
261
262    // Global cache object.
263    $cache = new Cache('global');
264    $cache->setParam(array('enabled' => true));
265
266
267SessionCache::putCache($val, $key)      $cache->set($key, $val)
268NOTE: notice method arguments have been reversed.
269
270SessionCache::getCache(...)             $cache->get(...)
271SessionCache::isCached(...)             $cache->exists(...)
272SessionCache::breakCache(...)           $cache->delete(...)
273
274
275=====================================================================
276Upload
277=====================================================================
278
279Change all object properties from direct access to method-access:
280
281$file->allow_overwriting = true;        $file->setParam('allow_overwriting', true);
282$file->valid_file_extensions = true;        $file->setParam('valid_file_extensions', true);
283$file->dest_file_perms = 0666;        $file->setParam('dest_file_perms', 0666);
284...etc.
285
286$file->setUploadPath(...)               $file->setParam(array('upload_path' => ...))
287
288
289=====================================================================
290Utilities
291=====================================================================
292
293humanFileSize($size, $unit, $format)    humanFileSize($size, $format, $max_unit)
294NOTE: changed interface
295
296dbArrayToList(...)                      escapedList(...)
297NOTE: The functionality of this has changed, better check output is valid.
298
299=====================================================================
300FormValidator
301=====================================================================
302
303include_once 'form_error_header.ihtml';      $fv->printErrorMessages();
Note: See TracBrowser for help on using the repository browser.