[763] | 1 | <HTML |
---|
| 2 | ><HEAD |
---|
| 3 | ><TITLE |
---|
| 4 | > Application setup files |
---|
| 5 | </TITLE |
---|
| 6 | ><META |
---|
| 7 | NAME="GENERATOR" |
---|
| 8 | CONTENT="Modular DocBook HTML Stylesheet Version 1.59"><LINK |
---|
| 9 | REL="HOME" |
---|
| 10 | TITLE=" eGroupWare Setup |
---|
| 11 | " |
---|
| 12 | HREF="setup3.html"><LINK |
---|
| 13 | REL="PREVIOUS" |
---|
| 14 | TITLE=" eGroupWare Setup |
---|
| 15 | " |
---|
| 16 | HREF="setup3.html"><LINK |
---|
| 17 | REL="NEXT" |
---|
| 18 | TITLE=" Developer Tools |
---|
| 19 | " |
---|
| 20 | HREF="setup3-2.html"></HEAD |
---|
| 21 | ><BODY |
---|
| 22 | CLASS="SECT1" |
---|
| 23 | ><DIV |
---|
| 24 | CLASS="NAVHEADER" |
---|
| 25 | ><TABLE |
---|
| 26 | WIDTH="100%" |
---|
| 27 | BORDER="0" |
---|
| 28 | CELLPADDING="0" |
---|
| 29 | CELLSPACING="0" |
---|
| 30 | ><TR |
---|
| 31 | ><TH |
---|
| 32 | COLSPAN="3" |
---|
| 33 | ALIGN="center" |
---|
| 34 | >eGroupWare Setup</TH |
---|
| 35 | ></TR |
---|
| 36 | ><TR |
---|
| 37 | ><TD |
---|
| 38 | WIDTH="10%" |
---|
| 39 | ALIGN="left" |
---|
| 40 | VALIGN="bottom" |
---|
| 41 | ><A |
---|
| 42 | HREF="setup3.html" |
---|
| 43 | >Prev</A |
---|
| 44 | ></TD |
---|
| 45 | ><TD |
---|
| 46 | WIDTH="80%" |
---|
| 47 | ALIGN="center" |
---|
| 48 | VALIGN="bottom" |
---|
| 49 | ></TD |
---|
| 50 | ><TD |
---|
| 51 | WIDTH="10%" |
---|
| 52 | ALIGN="right" |
---|
| 53 | VALIGN="bottom" |
---|
| 54 | ><A |
---|
| 55 | HREF="setup3-2.html" |
---|
| 56 | >Next</A |
---|
| 57 | ></TD |
---|
| 58 | ></TR |
---|
| 59 | ></TABLE |
---|
| 60 | ><HR |
---|
| 61 | ALIGN="LEFT" |
---|
| 62 | WIDTH="100%"></DIV |
---|
| 63 | ><DIV |
---|
| 64 | CLASS="SECT1" |
---|
| 65 | ><H1 |
---|
| 66 | CLASS="SECT1" |
---|
| 67 | ><A |
---|
| 68 | NAME="AEN22" |
---|
| 69 | >Application setup files</A |
---|
| 70 | ></H1 |
---|
| 71 | ><P |
---|
| 72 | > The files in this section are contained within each application/setup directory. Every app will some of these files in order to operate with setup3. |
---|
| 73 | </P |
---|
| 74 | ><DIV |
---|
| 75 | CLASS="SECT2" |
---|
| 76 | ><H2 |
---|
| 77 | CLASS="SECT2" |
---|
| 78 | ><A |
---|
| 79 | NAME="AEN25" |
---|
| 80 | >setup.inc.php (Required)</A |
---|
| 81 | ></H2 |
---|
| 82 | ><DIV |
---|
| 83 | CLASS="SECT3" |
---|
| 84 | ><H3 |
---|
| 85 | CLASS="SECT3" |
---|
| 86 | ><A |
---|
| 87 | NAME="AEN27" |
---|
| 88 | >Basic information</A |
---|
| 89 | ></H3 |
---|
| 90 | ><P |
---|
| 91 | > The values in this section must be used by all applications. |
---|
| 92 | </P |
---|
| 93 | ><P |
---|
| 94 | > The first section of setup.inc.php defines the very basic and yet critical information about the application. Take a look at the following section: |
---|
| 95 | </P |
---|
| 96 | ><TABLE |
---|
| 97 | BORDER="0" |
---|
| 98 | BGCOLOR="#E0E0E0" |
---|
| 99 | WIDTH="100%" |
---|
| 100 | ><TR |
---|
| 101 | ><TD |
---|
| 102 | ><PRE |
---|
| 103 | CLASS="PROGRAMLISTING" |
---|
| 104 | >$setup_info['addressbook']['name'] = 'addressbook'; |
---|
| 105 | $setup_info['addressbook']['title'] = 'Addressbook'; |
---|
| 106 | $setup_info['addressbook']['version'] = '0.9.13.002'; |
---|
| 107 | $setup_info['addressbook']['app_order'] = 4; |
---|
| 108 | $setup_info['addressbook']['enable'] = 1; |
---|
| 109 | </PRE |
---|
| 110 | ></TD |
---|
| 111 | ></TR |
---|
| 112 | ></TABLE |
---|
| 113 | ><P |
---|
| 114 | > 'name' is used throughout egroupware, typically in $phpgw_info flags such as 'currentapp' or as the 'app_name' almost everywhere else. |
---|
| 115 | </P |
---|
| 116 | ><P |
---|
| 117 | > 'title' would be used in the navbar, admin, preferences, as well as in the application itself. |
---|
| 118 | </P |
---|
| 119 | ><P |
---|
| 120 | > The 'version' string defines the version of the application and table code. This would be incremented whenever you create a new upgrade function, and typically only for table modifications. If the change is significant from the last code update, you could increment this here also. Incrementing this version string is not trivial, so please do read the rest of this document for more information about that. |
---|
| 121 | </P |
---|
| 122 | ><P |
---|
| 123 | > 'app_order' determines the order of applications in the navbar. If the number you set here is the same as is set for another app, the app whose 'name' is first in the English alphabet would appear first. Smaller numbers show closer to the top or left end of the navbar, depending upon the layout. |
---|
| 124 | </P |
---|
| 125 | ><P |
---|
| 126 | > The 'enable' string is used by the egroupware API to determine whether an application is disabled, enabled, or enabled but hidden from the navbar. Most applications will want this set to a value of 1 (enabled). The notifywindow app sets this to 2, which keeps it off the navbar. An enable of 0 would disable the app by default. There is one other special case, 3, which is used primarily by the API itself. From the perspective of setup3, the API is an application just like any other application. By setting the 'enable' flag to 3, the API is still enabled, but will not be assignable to a user as a real application. It will thereby be hidden from the admin for application and user/group editing. |
---|
| 127 | </P |
---|
| 128 | ></DIV |
---|
| 129 | ><DIV |
---|
| 130 | CLASS="SECT3" |
---|
| 131 | ><H3 |
---|
| 132 | CLASS="SECT3" |
---|
| 133 | ><A |
---|
| 134 | NAME="AEN37" |
---|
| 135 | >Table info</A |
---|
| 136 | ></H3 |
---|
| 137 | ><DIV |
---|
| 138 | CLASS="SECT4" |
---|
| 139 | ><H4 |
---|
| 140 | CLASS="SECT4" |
---|
| 141 | ><A |
---|
| 142 | NAME="AEN39" |
---|
| 143 | >Only applications with database tables will use entries in this section.</A |
---|
| 144 | ></H4 |
---|
| 145 | ><P |
---|
| 146 | > The next section of $setup_info values is an array defining all of the application's database tables: |
---|
| 147 | </P |
---|
| 148 | ><TABLE |
---|
| 149 | BORDER="0" |
---|
| 150 | BGCOLOR="#E0E0E0" |
---|
| 151 | WIDTH="100%" |
---|
| 152 | ><TR |
---|
| 153 | ><TD |
---|
| 154 | ><PRE |
---|
| 155 | CLASS="PROGRAMLISTING" |
---|
| 156 | >$setup_info['addressbook']['tables'] = array( |
---|
| 157 | 'phpgw_addressbook', |
---|
| 158 | 'phpgw_addressbook_extra' |
---|
| 159 | ); |
---|
| 160 | </PRE |
---|
| 161 | ></TD |
---|
| 162 | ></TR |
---|
| 163 | ></TABLE |
---|
| 164 | ><P |
---|
| 165 | > This is a simple array, and must list accurately the current table names you are using in your application. This list will match a much more complex array of table specifications, as you will see below. |
---|
| 166 | </P |
---|
| 167 | ></DIV |
---|
| 168 | ></DIV |
---|
| 169 | ><DIV |
---|
| 170 | CLASS="SECT3" |
---|
| 171 | ><H3 |
---|
| 172 | CLASS="SECT3" |
---|
| 173 | ><A |
---|
| 174 | NAME="AEN44" |
---|
| 175 | >Hooks</A |
---|
| 176 | ></H3 |
---|
| 177 | ><DIV |
---|
| 178 | CLASS="SECT4" |
---|
| 179 | ><H4 |
---|
| 180 | CLASS="SECT4" |
---|
| 181 | ><A |
---|
| 182 | NAME="AEN46" |
---|
| 183 | >Some applications will use this section.</A |
---|
| 184 | ></H4 |
---|
| 185 | ><P |
---|
| 186 | > The hooks array part of $setup_info contains a simple list of hooks the application will use: |
---|
| 187 | </P |
---|
| 188 | ><TABLE |
---|
| 189 | BORDER="0" |
---|
| 190 | BGCOLOR="#E0E0E0" |
---|
| 191 | WIDTH="100%" |
---|
| 192 | ><TR |
---|
| 193 | ><TD |
---|
| 194 | ><PRE |
---|
| 195 | CLASS="PROGRAMLISTING" |
---|
| 196 | >$setup_info['addressbook']['hooks'][] = 'preferences'; |
---|
| 197 | $setup_info['addressbook']['hooks'][] = 'admin'; |
---|
| 198 | </PRE |
---|
| 199 | ></TD |
---|
| 200 | ></TR |
---|
| 201 | ></TABLE |
---|
| 202 | ><P |
---|
| 203 | > Here we also note a different method of 'stuffing the array.' In any case, this list of hooks will be required soon in order for your hook_admin.inc.php and other files to work. This is being done to cut down on the manual directory listing and file_exists loops done currently to discover hook files. Other than 'preferences' and 'admin', 'home', 'manual', 'after_navbar' and 'navbar_end' are all valid hook entries. |
---|
| 204 | </P |
---|
| 205 | ></DIV |
---|
| 206 | ></DIV |
---|
| 207 | ><DIV |
---|
| 208 | CLASS="SECT3" |
---|
| 209 | ><H3 |
---|
| 210 | CLASS="SECT3" |
---|
| 211 | ><A |
---|
| 212 | NAME="AEN51" |
---|
| 213 | >Dependencies</A |
---|
| 214 | ></H3 |
---|
| 215 | ><DIV |
---|
| 216 | CLASS="SECT4" |
---|
| 217 | ><H4 |
---|
| 218 | CLASS="SECT4" |
---|
| 219 | ><A |
---|
| 220 | NAME="AEN53" |
---|
| 221 | >All applications will have at least one entry here.</A |
---|
| 222 | ></H4 |
---|
| 223 | ><P |
---|
| 224 | > The final section, or array of data, is a listing of the other applications your application requires in order to function: |
---|
| 225 | </P |
---|
| 226 | ><TABLE |
---|
| 227 | BORDER="0" |
---|
| 228 | BGCOLOR="#E0E0E0" |
---|
| 229 | WIDTH="100%" |
---|
| 230 | ><TR |
---|
| 231 | ><TD |
---|
| 232 | ><PRE |
---|
| 233 | CLASS="PROGRAMLISTING" |
---|
| 234 | >$setup_info['addressbook']['depends'][] = array( |
---|
| 235 | 'appname' => 'phpgwapi', |
---|
| 236 | 'versions' => Array( |
---|
| 237 | '0.9.10', |
---|
| 238 | '0.9.11', |
---|
| 239 | '0.9.12', |
---|
| 240 | '0.9.13' |
---|
| 241 | ) |
---|
| 242 | ); |
---|
| 243 | </PRE |
---|
| 244 | ></TD |
---|
| 245 | ></TR |
---|
| 246 | ></TABLE |
---|
| 247 | ><P |
---|
| 248 | > This is the standard dependency array for all egroupware applications. It states that this application requires the phpgwapi, and lists the versions with which versions this app is compatible. This list would need to be appended upon each new API release, assuming your application is compatible with this new API version. You may list other applications here, e.g. your app might depend upon 'email' in order to work properly. |
---|
| 249 | </P |
---|
| 250 | ><P |
---|
| 251 | > Do NOT list applications here without considering this: If you do list an application here, and your app does not really require it, your application will not install unless that other application is already installed. This is handled normally within the install/upgrade process loops, which will install only applications whose dependencies are satisfied. Using a multipass function, the applications are installed in the correct order to ensure that dependencies are resolved. In all cases, the API would be installed first in every new install or upgrade, since all applications depend on the API. |
---|
| 252 | </P |
---|
| 253 | ></DIV |
---|
| 254 | ></DIV |
---|
| 255 | ></DIV |
---|
| 256 | ><DIV |
---|
| 257 | CLASS="SECT2" |
---|
| 258 | ><H2 |
---|
| 259 | CLASS="SECT2" |
---|
| 260 | ><A |
---|
| 261 | NAME="AEN59" |
---|
| 262 | >tables_baseline.inc.php (Recommended)</A |
---|
| 263 | ></H2 |
---|
| 264 | ><DIV |
---|
| 265 | CLASS="SECT3" |
---|
| 266 | ><H3 |
---|
| 267 | CLASS="SECT3" |
---|
| 268 | ><A |
---|
| 269 | NAME="AEN61" |
---|
| 270 | >Any application that has at least one upgrade routine will have this file.</A |
---|
| 271 | ></H3 |
---|
| 272 | ><P |
---|
| 273 | > The tables_baseline file represents the earliest supported version of an application's tables. This file is used only in the upgrade process, and is critical to its success. It contains an array of database-independent table, field, key and index definitions. |
---|
| 274 | </P |
---|
| 275 | ><P |
---|
| 276 | > This array is formatted for use by the class.schema_proc_array.inc.php file in setup3. See the tables_update section below for more detail about schema_proc, but for now, here is a simple table definition in this format: |
---|
| 277 | </P |
---|
| 278 | ><TABLE |
---|
| 279 | BORDER="0" |
---|
| 280 | BGCOLOR="#E0E0E0" |
---|
| 281 | WIDTH="100%" |
---|
| 282 | ><TR |
---|
| 283 | ><TD |
---|
| 284 | ><PRE |
---|
| 285 | CLASS="PROGRAMLISTING" |
---|
| 286 | >$phpgw_baseline = array( |
---|
| 287 | 'skel' => array( |
---|
| 288 | 'fd' => array( |
---|
| 289 | 'skel_id' => array('type' => 'auto','nullable' => false), |
---|
| 290 | 'skel_owner' => array('type' => 'varchar','precision' => 25), |
---|
| 291 | 'skel_access' => array('type' => 'varchar','precision' => 10), |
---|
| 292 | 'skel_cat' => array('type' => 'int','precision' => 4), |
---|
| 293 | 'skel_des' => array('type' => 'text'), |
---|
| 294 | 'skel_pri' => array('type' => 'int','precision' => 4) |
---|
| 295 | ), |
---|
| 296 | 'pk' => array('skel_id'), |
---|
| 297 | 'fk' => array(), |
---|
| 298 | 'ix' => array(), |
---|
| 299 | 'uc' => array() |
---|
| 300 | ) |
---|
| 301 | ); |
---|
| 302 | </PRE |
---|
| 303 | ></TD |
---|
| 304 | ></TR |
---|
| 305 | ></TABLE |
---|
| 306 | ><P |
---|
| 307 | > This multi-dimensional array contains 1 subarray with 5 subs of its own. The first array ('skel' above) defines the table name. Below that are 5 sections, 'fd' for field definitions, 'pk' to define primary keys, 'fk' to define foreign keys, 'ix' to define indexed fields, and 'uc' to define columns that require unique values. In the above example, the table 'skel' has 6 fields (skel_id, skel_owner, skel_access, skel_cat, skel_des, skel_pri), and 'skel_id' is defined also as the primary key for this table. More information on this array is below. But, this format was chosen as an available solution for defining tables and fields without having to maintain seperate files for different databases. |
---|
| 308 | </P |
---|
| 309 | ></DIV |
---|
| 310 | ></DIV |
---|
| 311 | ><DIV |
---|
| 312 | CLASS="SECT2" |
---|
| 313 | ><H2 |
---|
| 314 | CLASS="SECT2" |
---|
| 315 | ><A |
---|
| 316 | NAME="AEN67" |
---|
| 317 | >tables_current.inc.php (Recommended)</A |
---|
| 318 | ></H2 |
---|
| 319 | ><DIV |
---|
| 320 | CLASS="SECT3" |
---|
| 321 | ><H3 |
---|
| 322 | CLASS="SECT3" |
---|
| 323 | ><A |
---|
| 324 | NAME="AEN69" |
---|
| 325 | >All applications with tables will need this file.</A |
---|
| 326 | ></H3 |
---|
| 327 | ><P |
---|
| 328 | > The tables_current file defines the current table definition that matches the 'version' string in $setup_info as well as the current code. This file is used only for new installs, or whenever the application is removed and reinstalled. The format and name of the array in this file is the same as for the tables_baseline file listed above. In fact, whenever it is required to change your table definitions, you would start by copying the current file over to become the tables_baseline file. After having created your upgrade routines, you would then recreate the current file to match the new table definitions. |
---|
| 329 | </P |
---|
| 330 | ></DIV |
---|
| 331 | ></DIV |
---|
| 332 | ><DIV |
---|
| 333 | CLASS="SECT2" |
---|
| 334 | ><H2 |
---|
| 335 | CLASS="SECT2" |
---|
| 336 | ><A |
---|
| 337 | NAME="AEN72" |
---|
| 338 | >tables_update.inc.php (Recommended)</A |
---|
| 339 | ></H2 |
---|
| 340 | ><DIV |
---|
| 341 | CLASS="SECT3" |
---|
| 342 | ><H3 |
---|
| 343 | CLASS="SECT3" |
---|
| 344 | ><A |
---|
| 345 | NAME="AEN74" |
---|
| 346 | >Any application which requires an upgrade to a previous version's tables will need this file.</A |
---|
| 347 | ></H3 |
---|
| 348 | ><P |
---|
| 349 | > This file will be the most complex of all setup-oriented files with which you will be working. It will contain all upgrade functions capable of upgrading any possible version of your egroupware app. These upgrade routines roughly match the old setup program's upgrade functions, but the use of objects and the methods have changed dramatically. The simplest version upgrade routine would look like: |
---|
| 350 | </P |
---|
| 351 | ><TABLE |
---|
| 352 | BORDER="0" |
---|
| 353 | BGCOLOR="#E0E0E0" |
---|
| 354 | WIDTH="100%" |
---|
| 355 | ><TR |
---|
| 356 | ><TD |
---|
| 357 | ><PRE |
---|
| 358 | CLASS="PROGRAMLISTING" |
---|
| 359 | >$test[] = "0.9.3pre10"; |
---|
| 360 | function addressbook_upgrade0_9_3pre10() |
---|
| 361 | { |
---|
| 362 | global $setup_info; |
---|
| 363 | $setup_info['addressbook']['currentver'] = '0.9.3'; |
---|
| 364 | return $setup_info['addressbook']['currentver']; |
---|
| 365 | } |
---|
| 366 | </PRE |
---|
| 367 | ></TD |
---|
| 368 | ></TR |
---|
| 369 | ></TABLE |
---|
| 370 | ><P |
---|
| 371 | > This upgrade function merely updates the current version number. Note that there is not only an upgrade function, but also the setting of a value in the $test array. The name 'test' is a holdover from the old setup program, and is an arbitrary choice. However, this name must be used for the upgrade process to work. Prior to each of your upgrade functions, add the value of the previous version to $test. |
---|
| 372 | </P |
---|
| 373 | ><P |
---|
| 374 | > Now look at the function name. The name is important and should be structured as the application name and the version from which you are intending to upgrade. The '.'s in the version string are replaced with '_'. |
---|
| 375 | </P |
---|
| 376 | ><P |
---|
| 377 | > Inside the function, we global the $setup_info array. Next, we alter the version number in that array, for our application. Please be careful to specify YOUR application name here. The very last thing we do is to return this new version to the calling function. The upgrade process relies on the value returned, since it uses this directly to determine the new version. This may appear illogical on some level, but it does work. The reason for returning this value instead of a True or 1, etc. has to do with variable scope and lifetime. In this way, even the globaling of $setup_info inside the function may have little effect on the upgrade process. But, there may be values in this array you would want to use within the function. More on that later. |
---|
| 378 | </P |
---|
| 379 | ><P |
---|
| 380 | > There is one other variable you would need if doing any database operations here. If you global $phpgw_setup, you will then have access to db and schema_proc objects and functions. The objects of interest here are: |
---|
| 381 | </P |
---|
| 382 | ><P |
---|
| 383 | ></P |
---|
| 384 | ><UL |
---|
| 385 | ><LI |
---|
| 386 | ><P |
---|
| 387 | > $phpgw_setup->oProc |
---|
| 388 | </P |
---|
| 389 | ></LI |
---|
| 390 | ><LI |
---|
| 391 | ><P |
---|
| 392 | > $phpgw_setup->db. |
---|
| 393 | </P |
---|
| 394 | ></LI |
---|
| 395 | ></UL |
---|
| 396 | ><P |
---|
| 397 | > For most database work you should use the oProc object. This also has a db object that should be used for most standard phpgw API db class functions, including $db->query, next_record, num_rows, and f. The use of these for standard db operations is critical to the upgrade process. Schema_proc has a flag that can be set to determine what mode of upgrade we are in. This flag is set in the setup class during the upgrade process, and should not be altered locally. |
---|
| 398 | </P |
---|
| 399 | ><P |
---|
| 400 | > This flag is a decision on whether to alter the database or the schema_proc array. The tables_baseline file above is loaded by setup prior to running your upgrade routines. If the current installed version is greater than the current upgrade routine, we don't need to alter the database yet. But schema_proc instead alters the $phpgw_baseline array in memory. The maintenance of this array is done even when we do alter the database. Once our version number in the test array matches the currently installed version of an application, real work on the tables begins. |
---|
| 401 | </P |
---|
| 402 | ><P |
---|
| 403 | > 'Why bother modifying this array at all', you may ask. The array must be maintained in order to keep current table definition status. This is used in some schema_proc functions when altering columns and tables. This is especially critical for pgsql schema_proc functions. |
---|
| 404 | </P |
---|
| 405 | ><P |
---|
| 406 | > By using the $phpgw_setup->oProc object for basic inserts and queries, we acheive the ability to run all upgrade functions in every upgrade cycle without actually altering the database until we reach the current version we actually want to upgrade. For example: |
---|
| 407 | </P |
---|
| 408 | ><TABLE |
---|
| 409 | BORDER="0" |
---|
| 410 | BGCOLOR="#E0E0E0" |
---|
| 411 | WIDTH="100%" |
---|
| 412 | ><TR |
---|
| 413 | ><TD |
---|
| 414 | ><PRE |
---|
| 415 | CLASS="PROGRAMLISTING" |
---|
| 416 | >$sql = "SELECT * FROM phpgw_addressbook_extra WHERE contact_name='notes'"; |
---|
| 417 | $phpgw_setup->oProc->query($sql,__LINE__,__FILE__); |
---|
| 418 | while($phpgw_setup->oProc->next_record()) { |
---|
| 419 | </PRE |
---|
| 420 | ></TD |
---|
| 421 | ></TR |
---|
| 422 | ></TABLE |
---|
| 423 | ><P |
---|
| 424 | > We could have used $phpgw_setup->db or even a copy for the above activity. However, using the above method ensures that an array only upgrade does just that. If the flag was set in setup telling schema_proc to alter the array only, we do not want to touch the tables for inserts or selects yet. In this case, $phpgw_setup->oProc->next_record() returns False, and the loop is skipped. The $phpgw_baseline array does not know about table content, only table and field definitions. |
---|
| 425 | </P |
---|
| 426 | ><P |
---|
| 427 | > If the upgrade function containing this method is actually working on the tables (currentver <= the upgrade function), then next_record() is returned as the expected action of pulling the next row of data. Inside of this while loop, you can safely use $phpgw_setup->db, or preferably a copy, to do the insert/delete, etc you want to have happen here. |
---|
| 428 | </P |
---|
| 429 | ><TABLE |
---|
| 430 | BORDER="0" |
---|
| 431 | BGCOLOR="#E0E0E0" |
---|
| 432 | WIDTH="100%" |
---|
| 433 | ><TR |
---|
| 434 | ><TD |
---|
| 435 | ><PRE |
---|
| 436 | CLASS="PROGRAMLISTING" |
---|
| 437 | > $cid = $phpgw_setup->oProc->f('contact_id'); |
---|
| 438 | $cvalu = $phpgw_setup->oProc->f('contact_value'); |
---|
| 439 | $update = "UPDATE phpgw_addressbook set note='" . $cvalu . "' WHERE id=" . $cid; |
---|
| 440 | $db1->query($update); |
---|
| 441 | $delete = "DELETE FROM phpgw_addressbook_extra WHERE contact_id=" . $cid . " AND contact_name='notes'"; |
---|
| 442 | $db1->query($delete); |
---|
| 443 | } |
---|
| 444 | </PRE |
---|
| 445 | ></TD |
---|
| 446 | ></TR |
---|
| 447 | ></TABLE |
---|
| 448 | ><P |
---|
| 449 | > $db1 is a copy of $phpgw_setup->db, to avoid potential conflicts with the rest of setup's db activities. |
---|
| 450 | </P |
---|
| 451 | ><P |
---|
| 452 | > In addition to the basic API db class functions, schema_proc introduces the following special functions: |
---|
| 453 | </P |
---|
| 454 | ><TABLE |
---|
| 455 | BORDER="0" |
---|
| 456 | BGCOLOR="#E0E0E0" |
---|
| 457 | WIDTH="100%" |
---|
| 458 | ><TR |
---|
| 459 | ><TD |
---|
| 460 | ><PRE |
---|
| 461 | CLASS="PROGRAMLISTING" |
---|
| 462 | >function DropTable($sTableName) |
---|
| 463 | function DropColumn($sTableName, $aTableDef, $sColumnName) |
---|
| 464 | function RenameTable($sOldTableName, $sNewTableName) |
---|
| 465 | function RenameColumn($sTableName, $sOldColumnName, $sNewColumnName) |
---|
| 466 | function AlterColumn($sTableName, $sColumnName, $aColumnDef) |
---|
| 467 | function AddColumn($sTableName, $sColumnName, $aColumnDef) |
---|
| 468 | function CreateTable($sTableName, $aTableDef) |
---|
| 469 | </PRE |
---|
| 470 | ></TD |
---|
| 471 | ></TR |
---|
| 472 | ></TABLE |
---|
| 473 | ><P |
---|
| 474 | > Please use these functions where appropriate in place of standard SQL CREATE, DROP, and ALTER TABLE commands. This will ensure that your upgrade script works for all supported databases. |
---|
| 475 | </P |
---|
| 476 | ><P |
---|
| 477 | > Of these functions, DropTable, RenameTable, and RenameColumn are pretty straightforward. Pass these the table names you wish to Drop/Rename, and schema_proc will handle the rest, including indexes and sequences, where applicable. |
---|
| 478 | </P |
---|
| 479 | ><P |
---|
| 480 | > The remaining functions require some explanation: |
---|
| 481 | </P |
---|
| 482 | ><P |
---|
| 483 | ></P |
---|
| 484 | ><UL |
---|
| 485 | ><LI |
---|
| 486 | ><P |
---|
| 487 | > CreateTable: |
---|
| 488 | </P |
---|
| 489 | ></LI |
---|
| 490 | ></UL |
---|
| 491 | ><TABLE |
---|
| 492 | BORDER="0" |
---|
| 493 | BGCOLOR="#E0E0E0" |
---|
| 494 | WIDTH="100%" |
---|
| 495 | ><TR |
---|
| 496 | ><TD |
---|
| 497 | ><PRE |
---|
| 498 | CLASS="PROGRAMLISTING" |
---|
| 499 | >$phpgw_setup->oProc->CreateTable( |
---|
| 500 | 'categories', array( |
---|
| 501 | 'fd' => array( |
---|
| 502 | 'cat_id' => array('type' => 'auto','nullable' => false), |
---|
| 503 | 'account_id' => array('type' => 'int','precision' => 4,'nullable' => false, 'default' => 0), |
---|
| 504 | 'app_name' => array('type' => 'varchar','precision' => 25,'nullable' => false), |
---|
| 505 | 'cat_name' => array('type' => 'varchar', 'precision' => 150, 'nullable' => false), |
---|
| 506 | 'cat_description' => array('type' => 'text', 'nullable' => false) |
---|
| 507 | ), |
---|
| 508 | 'pk' => array('cat_id'), |
---|
| 509 | 'ix' => array(), |
---|
| 510 | 'fk' => array(), |
---|
| 511 | 'uc' => array() |
---|
| 512 | ) |
---|
| 513 | ); |
---|
| 514 | </PRE |
---|
| 515 | ></TD |
---|
| 516 | ></TR |
---|
| 517 | ></TABLE |
---|
| 518 | ><P |
---|
| 519 | > Does this look familiar? The array passed to CreateTable is in the format used also in tables_baseline and tables_current. Note a slight difference where the table name is being passed as a seperate argument. The second argument to the function is the table definition array, starting with 'fd'. |
---|
| 520 | </P |
---|
| 521 | ><P |
---|
| 522 | ></P |
---|
| 523 | ><UL |
---|
| 524 | ><LI |
---|
| 525 | ><P |
---|
| 526 | > AddColumn: |
---|
| 527 | </P |
---|
| 528 | ></LI |
---|
| 529 | ></UL |
---|
| 530 | ><TABLE |
---|
| 531 | BORDER="0" |
---|
| 532 | BGCOLOR="#E0E0E0" |
---|
| 533 | WIDTH="100%" |
---|
| 534 | ><TR |
---|
| 535 | ><TD |
---|
| 536 | ><PRE |
---|
| 537 | CLASS="PROGRAMLISTING" |
---|
| 538 | >$phpgw_setup->oProc->AddColumn('phpgw_categories','cat_access',array('type' => 'varchar', 'precision' => 25)); |
---|
| 539 | </PRE |
---|
| 540 | ></TD |
---|
| 541 | ></TR |
---|
| 542 | ></TABLE |
---|
| 543 | ><P |
---|
| 544 | > Here we pass the table name of an existing table, the new column name, and a field definition. This definition is merely a slice of the table arrays found earlier in this document. |
---|
| 545 | </P |
---|
| 546 | ><P |
---|
| 547 | ></P |
---|
| 548 | ><UL |
---|
| 549 | ><LI |
---|
| 550 | ><P |
---|
| 551 | > AlterColumn: |
---|
| 552 | </P |
---|
| 553 | ></LI |
---|
| 554 | ></UL |
---|
| 555 | ><TABLE |
---|
| 556 | BORDER="0" |
---|
| 557 | BGCOLOR="#E0E0E0" |
---|
| 558 | WIDTH="100%" |
---|
| 559 | ><TR |
---|
| 560 | ><TD |
---|
| 561 | ><PRE |
---|
| 562 | CLASS="PROGRAMLISTING" |
---|
| 563 | >$phpgw_setup->oProc->AlterColumn('phpgw_sessions','session_action',array('type' => 'varchar', 'precision' => '255')); |
---|
| 564 | </PRE |
---|
| 565 | ></TD |
---|
| 566 | ></TR |
---|
| 567 | ></TABLE |
---|
| 568 | ><P |
---|
| 569 | > The format of this function matches AddColumn. It is also a simple case of passing the table name, field name, and field definition. |
---|
| 570 | </P |
---|
| 571 | ><P |
---|
| 572 | ></P |
---|
| 573 | ><UL |
---|
| 574 | ><LI |
---|
| 575 | ><P |
---|
| 576 | > DropColumn: |
---|
| 577 | </P |
---|
| 578 | ></LI |
---|
| 579 | ></UL |
---|
| 580 | ><TABLE |
---|
| 581 | BORDER="0" |
---|
| 582 | BGCOLOR="#E0E0E0" |
---|
| 583 | WIDTH="100%" |
---|
| 584 | ><TR |
---|
| 585 | ><TD |
---|
| 586 | ><PRE |
---|
| 587 | CLASS="PROGRAMLISTING" |
---|
| 588 | >$newtbldef = array( |
---|
| 589 | "fd" => array( |
---|
| 590 | 'acl_appname' => array('type' => 'varchar', 'precision' => 50), |
---|
| 591 | 'acl_location' => array('type' => 'varchar', 'precision' => 255), |
---|
| 592 | 'acl_account' => array('type' => 'int', 'precision' => 4), |
---|
| 593 | 'acl_rights' => array('type' => 'int', 'precision' => 4) |
---|
| 594 | ), |
---|
| 595 | 'pk' => array(), |
---|
| 596 | 'ix' => array(), |
---|
| 597 | 'fk' => array(), |
---|
| 598 | 'uc' => array() |
---|
| 599 | ); |
---|
| 600 | $phpgw_setup->oProc->DropColumn('phpgw_acl',$newtbldef,'acl_account_type'); |
---|
| 601 | </PRE |
---|
| 602 | ></TD |
---|
| 603 | ></TR |
---|
| 604 | ></TABLE |
---|
| 605 | ><P |
---|
| 606 | > This is the most complicated function in schema_proc, from the user's perspective. Its complexity is necessitated by the requirement of some databases to recreate a table in the case of dropping a column. Note that the table definition array is being used yet again. The array defined here should match the table definition you want after this function has completed. Here, we are dropping the column 'acl_account_type' from the table 'phpgw_acl', and the table definition does not have this column defined. You could copy information from your tables_current file here and edit it to match the desired new table spec, less the column you wish to drop. |
---|
| 607 | </P |
---|
| 608 | ><P |
---|
| 609 | > There are additional functions within schema_proc, the majority of which are not to be called directly. They are used internally. If you do wish to investigate further, use class.schema_proc.inc.php as your guide. This master file includes the class.schema_proc_DBMS.inc.php and class.schema_proc_array.inc.php files. The DBMS files should not be used as a guide, since their functions are called from the master class, and the parameters are different from what you might expect relative to the master. |
---|
| 610 | </P |
---|
| 611 | ><P |
---|
| 612 | > PLEASE, DO NOT WRITE TO OR ALTER ANOTHER APPLICATION'S TABLES OR THE API TABLES IN YOUR APPLICATION UPGRADE FUNCTIONS! |
---|
| 613 | </P |
---|
| 614 | ></DIV |
---|
| 615 | ></DIV |
---|
| 616 | ><DIV |
---|
| 617 | CLASS="SECT2" |
---|
| 618 | ><H2 |
---|
| 619 | CLASS="SECT2" |
---|
| 620 | ><A |
---|
| 621 | NAME="AEN123" |
---|
| 622 | >default_records.inc.php (Optional)</A |
---|
| 623 | ></H2 |
---|
| 624 | ><DIV |
---|
| 625 | CLASS="SECT3" |
---|
| 626 | ><H3 |
---|
| 627 | CLASS="SECT3" |
---|
| 628 | ><A |
---|
| 629 | NAME="AEN125" |
---|
| 630 | >Any application with tables that wants to load some default data will need this file.</A |
---|
| 631 | ></H3 |
---|
| 632 | ><P |
---|
| 633 | > The default_records file consists of a list of SQL INSERTs using the $oProc object directly: |
---|
| 634 | </P |
---|
| 635 | ><TABLE |
---|
| 636 | BORDER="0" |
---|
| 637 | BGCOLOR="#E0E0E0" |
---|
| 638 | WIDTH="100%" |
---|
| 639 | ><TR |
---|
| 640 | ><TD |
---|
| 641 | ><PRE |
---|
| 642 | CLASS="PROGRAMLISTING" |
---|
| 643 | >$oProc->query("INSERT INTO phpgw_inv_statuslist (status_name) VALUES ('available')"); |
---|
| 644 | $oProc->query("INSERT INTO phpgw_inv_statuslist (status_name) VALUES ('no longer available')"); |
---|
| 645 | $oProc->query("INSERT INTO phpgw_inv_statuslist (status_name) VALUES ('back order')"); |
---|
| 646 | </PRE |
---|
| 647 | ></TD |
---|
| 648 | ></TR |
---|
| 649 | ></TABLE |
---|
| 650 | ><P |
---|
| 651 | > In this case, the developer wanted to insert some status information, which was then used in a select box on an html form. Using the default_records file, every new install will have this data included. This file should consist of queries applicable to the tables defined in setup.inc.php and tables_current.inc.php. |
---|
| 652 | </P |
---|
| 653 | ></DIV |
---|
| 654 | ></DIV |
---|
| 655 | ><DIV |
---|
| 656 | CLASS="SECT2" |
---|
| 657 | ><H2 |
---|
| 658 | CLASS="SECT2" |
---|
| 659 | ><A |
---|
| 660 | NAME="AEN130" |
---|
| 661 | >test_data.inc.php (Optional)</A |
---|
| 662 | ></H2 |
---|
| 663 | ><DIV |
---|
| 664 | CLASS="SECT3" |
---|
| 665 | ><H3 |
---|
| 666 | CLASS="SECT3" |
---|
| 667 | ><A |
---|
| 668 | NAME="AEN132" |
---|
| 669 | >Any developer wanting to test the full list of upgrade routines can use this file.</A |
---|
| 670 | ></H3 |
---|
| 671 | ><P |
---|
| 672 | > test_data.inc.php is similar to default_records above. It is called only by schematoy.php and is never installed with a new install or upgrade. This is a developer-only file. The INSERTs here should be applicable to the tables_baseline table definitions. |
---|
| 673 | </P |
---|
| 674 | ></DIV |
---|
| 675 | ></DIV |
---|
| 676 | ><DIV |
---|
| 677 | CLASS="SECT2" |
---|
| 678 | ><H2 |
---|
| 679 | CLASS="SECT2" |
---|
| 680 | ><A |
---|
| 681 | NAME="AEN135" |
---|
| 682 | >language files (Required)</A |
---|
| 683 | ></H2 |
---|
| 684 | ><DIV |
---|
| 685 | CLASS="SECT3" |
---|
| 686 | ><H3 |
---|
| 687 | CLASS="SECT3" |
---|
| 688 | ><A |
---|
| 689 | NAME="AEN137" |
---|
| 690 | >All applications should have at least a file of English translations, used for their application lang() calls.</A |
---|
| 691 | ></H3 |
---|
| 692 | ><P |
---|
| 693 | ></P |
---|
| 694 | ><UL |
---|
| 695 | ><LI |
---|
| 696 | ><P |
---|
| 697 | > Format of a lang file: |
---|
| 698 | </P |
---|
| 699 | ></LI |
---|
| 700 | ></UL |
---|
| 701 | ><TABLE |
---|
| 702 | BORDER="0" |
---|
| 703 | BGCOLOR="#E0E0E0" |
---|
| 704 | WIDTH="100%" |
---|
| 705 | ><TR |
---|
| 706 | ><TD |
---|
| 707 | ><PRE |
---|
| 708 | CLASS="PROGRAMLISTING" |
---|
| 709 | >{phrase}{TAB}{appname}{TAB}{LANG_CODE}{TAB}{translation} |
---|
| 710 | e.g: |
---|
| 711 | first name common en First Name |
---|
| 712 | first name common de Vorname |
---|
| 713 | </PRE |
---|
| 714 | ></TD |
---|
| 715 | ></TR |
---|
| 716 | ></TABLE |
---|
| 717 | ><P |
---|
| 718 | ></P |
---|
| 719 | ><UL |
---|
| 720 | ><LI |
---|
| 721 | ><P |
---|
| 722 | > Filenames: |
---|
| 723 | </P |
---|
| 724 | ></LI |
---|
| 725 | ></UL |
---|
| 726 | ><TABLE |
---|
| 727 | BORDER="0" |
---|
| 728 | BGCOLOR="#E0E0E0" |
---|
| 729 | WIDTH="100%" |
---|
| 730 | ><TR |
---|
| 731 | ><TD |
---|
| 732 | ><PRE |
---|
| 733 | CLASS="PROGRAMLISTING" |
---|
| 734 | >phpgw_{LANG_CODE}.lang |
---|
| 735 | e.g. |
---|
| 736 | English: phpgw_en.lang |
---|
| 737 | German: phpgw_de.lang |
---|
| 738 | </PRE |
---|
| 739 | ></TD |
---|
| 740 | ></TR |
---|
| 741 | ></TABLE |
---|
| 742 | ><P |
---|
| 743 | > Please see the contents of the API 'languages' table for the correct setting of the LANG_CODE. |
---|
| 744 | </P |
---|
| 745 | ></DIV |
---|
| 746 | ></DIV |
---|
| 747 | ></DIV |
---|
| 748 | ><DIV |
---|
| 749 | CLASS="NAVFOOTER" |
---|
| 750 | ><HR |
---|
| 751 | ALIGN="LEFT" |
---|
| 752 | WIDTH="100%"><TABLE |
---|
| 753 | WIDTH="100%" |
---|
| 754 | BORDER="0" |
---|
| 755 | CELLPADDING="0" |
---|
| 756 | CELLSPACING="0" |
---|
| 757 | ><TR |
---|
| 758 | ><TD |
---|
| 759 | WIDTH="33%" |
---|
| 760 | ALIGN="left" |
---|
| 761 | VALIGN="top" |
---|
| 762 | ><A |
---|
| 763 | HREF="setup3.html" |
---|
| 764 | >Prev</A |
---|
| 765 | ></TD |
---|
| 766 | ><TD |
---|
| 767 | WIDTH="34%" |
---|
| 768 | ALIGN="center" |
---|
| 769 | VALIGN="top" |
---|
| 770 | ><A |
---|
| 771 | HREF="setup3.html" |
---|
| 772 | >Home</A |
---|
| 773 | ></TD |
---|
| 774 | ><TD |
---|
| 775 | WIDTH="33%" |
---|
| 776 | ALIGN="right" |
---|
| 777 | VALIGN="top" |
---|
| 778 | ><A |
---|
| 779 | HREF="setup3-2.html" |
---|
| 780 | >Next</A |
---|
| 781 | ></TD |
---|
| 782 | ></TR |
---|
| 783 | ><TR |
---|
| 784 | ><TD |
---|
| 785 | WIDTH="33%" |
---|
| 786 | ALIGN="left" |
---|
| 787 | VALIGN="top" |
---|
| 788 | >eGroupWare Setup</TD |
---|
| 789 | ><TD |
---|
| 790 | WIDTH="34%" |
---|
| 791 | ALIGN="center" |
---|
| 792 | VALIGN="top" |
---|
| 793 | > </TD |
---|
| 794 | ><TD |
---|
| 795 | WIDTH="33%" |
---|
| 796 | ALIGN="right" |
---|
| 797 | VALIGN="top" |
---|
| 798 | >Developer Tools</TD |
---|
| 799 | ></TR |
---|
| 800 | ></TABLE |
---|
| 801 | ></DIV |
---|
| 802 | ></BODY |
---|
| 803 | ></HTML |
---|
| 804 | > |
---|