| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Rev: 427 $ | $LastChangedBy: nate $ |
|---|
| 4 | $LastChangedDate: 2008-08-13 12:09:00 -0600 (Wed, 13 Aug 2008) $ |
|---|
| 5 | +-------------------------------------------------------------------------+ |
|---|
| 6 | | Copyright (c) 2004 - 2010, Kreotek LLC | |
|---|
| 7 | | All rights reserved. | |
|---|
| 8 | +-------------------------------------------------------------------------+ |
|---|
| 9 | | | |
|---|
| 10 | | Redistribution and use in source and binary forms, with or without | |
|---|
| 11 | | modification, are permitted provided that the following conditions are | |
|---|
| 12 | | met: | |
|---|
| 13 | | | |
|---|
| 14 | | - Redistributions of source code must retain the above copyright | |
|---|
| 15 | | notice, this list of conditions and the following disclaimer. | |
|---|
| 16 | | | |
|---|
| 17 | | - Redistributions in binary form must reproduce the above copyright | |
|---|
| 18 | | notice, this list of conditions and the following disclaimer in the | |
|---|
| 19 | | documentation and/or other materials provided with the distribution. | |
|---|
| 20 | | | |
|---|
| 21 | | - Neither the name of Kreotek LLC nor the names of its contributore may | |
|---|
| 22 | | be used to endorse or promote products derived from this software | |
|---|
| 23 | | without specific prior written permission. | |
|---|
| 24 | | | |
|---|
| 25 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|---|
| 26 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|---|
| 27 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
|---|
| 28 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
|---|
| 29 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
|---|
| 30 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
|---|
| 31 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
|---|
| 32 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
|---|
| 33 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
|---|
| 34 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
|---|
| 35 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|---|
| 36 | | | |
|---|
| 37 | +-------------------------------------------------------------------------+ |
|---|
| 38 | */ |
|---|
| 39 | define("APP_DEBUG",false); |
|---|
| 40 | define("noStartup",true); |
|---|
| 41 | |
|---|
| 42 | require("install_include.php"); |
|---|
| 43 | require("../include/session.php"); |
|---|
| 44 | require("../include/common_functions.php"); |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | class generateUUIDS extends installUpdateBase{ |
|---|
| 48 | |
|---|
| 49 | var $userList; |
|---|
| 50 | var $roleList; |
|---|
| 51 | var $tabledefList; |
|---|
| 52 | var $moduleList; |
|---|
| 53 | var $receiptList; |
|---|
| 54 | var $invoiceList; |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | function process(){ |
|---|
| 58 | |
|---|
| 59 | $this->phpbmsSession = new phpbmsSession; |
|---|
| 60 | |
|---|
| 61 | if($this->phpbmsSession->loadDBSettings(false)){ |
|---|
| 62 | |
|---|
| 63 | @ include_once("include/db.php"); |
|---|
| 64 | |
|---|
| 65 | $this->db = new db(false); |
|---|
| 66 | $this->db->stopOnError = false; |
|---|
| 67 | $this->db->showError = false; |
|---|
| 68 | $this->db->logError = false; |
|---|
| 69 | |
|---|
| 70 | } else |
|---|
| 71 | return $this->returnJSON(false, "Could not open session.php file"); |
|---|
| 72 | |
|---|
| 73 | if(!$this->db->connect()) |
|---|
| 74 | return $this->returnJSON(false, "Could not connect to database ".$this->db->getError()); |
|---|
| 75 | |
|---|
| 76 | if(!$this->db->selectSchema()) |
|---|
| 77 | return $this->returnJSON(false, "Could not open database schema '".MYSQL_DATABASE."'"); |
|---|
| 78 | |
|---|
| 79 | //generate base uuids for tables |
|---|
| 80 | $this->createUUIDs("tbld:afe6d297-b484-4f0b-57d4-1c39412e9dfb"); //Users |
|---|
| 81 | $this->createUUIDs("tbld:8d19c73c-42fb-d829-3681-d20b4dbe43b9"); //Relationships |
|---|
| 82 | $this->createUUIDs("tbld:5c9d645f-26ab-5003-b98e-89e9049f8ac3"); //Table Definitions |
|---|
| 83 | $this->createUUIDs("tbld:a4cdd991-cf0a-916f-1240-49428ea1bdd1"); //Notes |
|---|
| 84 | $this->createUUIDs("tbld:d595ef42-db9d-2233-1b9b-11dfd0db9cbb"); //Reports |
|---|
| 85 | $this->createUUIDs("tbld:e251524a-2da4-a0c9-8725-d3d0412d8f4a"); //Saved Searches/Sorts |
|---|
| 86 | $this->createUUIDs("tbld:ea159d67-5e89-5b7f-f5a0-c740e147cd73"); //Installed Modules |
|---|
| 87 | $this->createUUIDs("tbld:80b4f38d-b957-bced-c0a0-ed08a0db6475"); //Files |
|---|
| 88 | $this->createUUIDs("tbld:87b9fe06-afe5-d9c6-0fa0-4a0f2ec4ee8a"); //Roles |
|---|
| 89 | $this->createUUIDs("tbld:83de284b-ef79-3567-145c-30ca38b40796"); //Scheduler |
|---|
| 90 | $this->createUUIDs("tbld:7e75af48-6f70-d157-f440-69a8e7f59d38"); //Tabs |
|---|
| 91 | $this->createUUIDs("tbld:29925e0a-c825-0067-8882-db4b57866a96"); //Smart Searches |
|---|
| 92 | $this->createUUIDs("tbld:83187e3d-101e-a8a5-037f-31e9800fed2d"); //Menu |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | //generate lists used elsewhere |
|---|
| 96 | $this->moduleList = $this->generateUUIDList("modules"); |
|---|
| 97 | |
|---|
| 98 | $bmsModulePresent = false; |
|---|
| 99 | if(in_array("mod:0aa9cca0-7388-0eae-81b9-9935f9d127cc", $this->moduleList)) |
|---|
| 100 | $bmsModulePresent = true; |
|---|
| 101 | |
|---|
| 102 | //BMS updates |
|---|
| 103 | if($bmsModulePresent){ |
|---|
| 104 | |
|---|
| 105 | $this->createUUIDs("tbld:c9ff2c8c-ce1f-659a-9c55-31bca7cce70e"); //tax |
|---|
| 106 | $this->createUUIDs("tbld:d6e4e1fb-4bfa-cb53-ab9c-1b3e7f907ae2"); //invoicestatuses |
|---|
| 107 | $this->createUUIDs("tbld:380d4efa-a825-f377-6fa1-a030b8c58ffe"); //payment methods |
|---|
| 108 | $this->createUUIDs("tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083"); //clients |
|---|
| 109 | $this->createUUIDs("tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883"); //invoices |
|---|
| 110 | $this->createUUIDs("tbld:455b8839-162b-3fcb-64b6-eeb946f873e1"); //discounts |
|---|
| 111 | $this->createUUIDs("tbld:fa8a0ddc-87d3-a9e9-60b0-1bab374b2993"); //shipping methods |
|---|
| 112 | $this->createUUIDs("tbld:7a9e87ed-d165-c4a4-d9b9-0a4adc3c5a34"); //products |
|---|
| 113 | $this->createUUIDs("tbld:3342a3d4-c6a2-3a38-6576-419299859561"); //product categories |
|---|
| 114 | $this->createUUIDs("tbld:27b99bda-7bec-b152-8397-a3b09c74cb23"); //addresses |
|---|
| 115 | $this->createUUIDs("tbld:c595dbe7-6c77-1e02-5e81-c2e215736e9c"); //aritems |
|---|
| 116 | $this->createUUIDs("tbld:43678406-be25-909b-c715-7e2afc7db601"); //receipts |
|---|
| 117 | |
|---|
| 118 | $this->aritemList = $this->generateUUIDList("aritems"); |
|---|
| 119 | $this->receiptList = $this->generateUUIDList("receipts"); |
|---|
| 120 | $this->productsList = $this->generateUUIDList("products"); |
|---|
| 121 | $this->addressList = $this->generateUUIDList("addresses"); |
|---|
| 122 | $this->productcatList = $this->generateUUIDList("productcategories"); |
|---|
| 123 | $this->productList = $this->generateUUIDList("products"); |
|---|
| 124 | $this->clientList = $this->generateUUIDList("clients"); |
|---|
| 125 | $this->statusList = $this->generateUUIDList("invoicestatuses"); |
|---|
| 126 | $this->discountList = $this->generateUUIDList("discounts"); |
|---|
| 127 | $this->discountList[0] = ""; |
|---|
| 128 | $this->taxList = $this->generateUUIDList("tax"); |
|---|
| 129 | $this->taxList[0] = ""; |
|---|
| 130 | $this->shippingList = $this->generateUUIDList("shippingmethods"); |
|---|
| 131 | $this->shippingList[0] = ""; |
|---|
| 132 | $this->paymentList = $this->generateUUIDList("paymentmethods"); |
|---|
| 133 | $this->paymentList[0] = ""; |
|---|
| 134 | $this->invoiceList = $this->generateUUIDList("invoices"); |
|---|
| 135 | $this->invoiceStatusList = $this->generateUUIDList("invoicestatuses"); |
|---|
| 136 | |
|---|
| 137 | }//endif |
|---|
| 138 | |
|---|
| 139 | $this->tabledefList = $this->generateUUIDList("tabledefs"); |
|---|
| 140 | |
|---|
| 141 | $this->userList = $this->generateUUIDList("users"); |
|---|
| 142 | $this->userList[0] =""; |
|---|
| 143 | |
|---|
| 144 | $this->roleList = $this->generateUUIDList("roles"); |
|---|
| 145 | $this->roleList[-100] = "Admin"; |
|---|
| 146 | $this->roleList[0] = ""; |
|---|
| 147 | |
|---|
| 148 | $this->tabledefList = $this->generateUUIDList("tabledefs"); |
|---|
| 149 | $this->moduleList= $this->generateUUIDList("modules"); |
|---|
| 150 | $this->fileList= $this->generateUUIDList("files"); |
|---|
| 151 | |
|---|
| 152 | $menuList = $this->generateUUIDList("menu"); |
|---|
| 153 | $menuList[0] = ""; |
|---|
| 154 | |
|---|
| 155 | $notesList = $this->generateUUIDList("notes"); |
|---|
| 156 | |
|---|
| 157 | //function calls for all we have to do go here |
|---|
| 158 | //====================================================================== |
|---|
| 159 | $this->updateFields("reports", array("roleid"=>$this->roleList, "tabledefid"=>$this->tabledefList)); |
|---|
| 160 | $this->updateFields("rolestousers", array("userid"=>$this->userList, "roleid"=>$this->roleList)); |
|---|
| 161 | $this->updateFields("tablecolumns", array("tabledefid"=>$this->tabledefList, "roleid"=>$this->roleList)); |
|---|
| 162 | $this->updateFields("tablefindoptions", array("tabledefid"=>$this->tabledefList, "roleid"=>$this->roleList)); |
|---|
| 163 | $this->updateFields("tablegroupings", array("tabledefid"=>$this->tabledefList, "roleid"=>$this->roleList)); |
|---|
| 164 | $this->updateFields("tableoptions", array("tabledefid"=>$this->tabledefList, "roleid"=>$this->roleList)); |
|---|
| 165 | $this->updateFields("tabledefs", array("moduleid"=>$this->moduleList, "editroleid"=>$this->roleList, "addroleid"=>$this->roleList, "searchroleid"=>$this->roleList, "advsearchroleid"=>$this->roleList, "viewsqlroleid"=>$this->roleList)); |
|---|
| 166 | $this->updateFields("tablesearchablefields", array("tabledefid"=>$this->tabledefList)); |
|---|
| 167 | $this->updateFields("widgets", array("roleid"=>$this->roleList, "moduleid"=>$this->moduleList)); |
|---|
| 168 | $this->updateFields("usersearches", array("tabledefid"=>$this->tabledefList, "userid"=>$this->userList, "roleid"=>$this->roleList)); |
|---|
| 169 | $this->updateFields("relationships", array("fromtableid"=>$this->tabledefList, "totableid"=>$this->tabledefList)); |
|---|
| 170 | |
|---|
| 171 | $this->updateFields("files", array("roleid"=>$this->roleList)); |
|---|
| 172 | $this->updateFields("attachments", array("fileid"=>$this->fileList, "tabledefid"=>$this->tabledefList)); |
|---|
| 173 | $this->updateFields("menu", array("parentid"=>$menuList, "roleid"=>$this->roleList)); |
|---|
| 174 | $this->updateFields("smartsearches", array("tabledefid"=>$this->tabledefList, "moduleid"=>$this->moduleList)); |
|---|
| 175 | $this->updateFields("tabs", array("roleid"=>$this->roleList)); |
|---|
| 176 | $this->updateFields("notes", array("assignedtoid"=>$this->userList, "assignedbyid"=>$this->userList, "attachedtabledefid"=>$this->tabledefList, "parentid"=>$notesList)); |
|---|
| 177 | $this->updateFields("log", array("userid"=>$this->userList)); |
|---|
| 178 | |
|---|
| 179 | //custom stuff |
|---|
| 180 | $this->updateMenuLinks(); |
|---|
| 181 | |
|---|
| 182 | //BMS updates |
|---|
| 183 | if($bmsModulePresent){ |
|---|
| 184 | |
|---|
| 185 | $this->updateFields("products", array("categoryid"=>$this->productcatList)); |
|---|
| 186 | |
|---|
| 187 | $invoiceArray = array( |
|---|
| 188 | "clientid" =>$this->clientList, |
|---|
| 189 | "statusid" =>$this->statusList, |
|---|
| 190 | "assignedtoid" =>$this->userList, |
|---|
| 191 | "discountid" =>$this->discountList, |
|---|
| 192 | "taxareaid" =>$this->taxList, |
|---|
| 193 | "shippingmethodid"=>$this->shippingList, |
|---|
| 194 | "paymentmethodid" =>$this->paymentList |
|---|
| 195 | ); |
|---|
| 196 | $this->updateFields("invoices", $invoiceArray); |
|---|
| 197 | |
|---|
| 198 | $clientArray = array( |
|---|
| 199 | "taxareaid" =>$this->taxList, |
|---|
| 200 | "shippingmethodid" =>$this->shippingList, |
|---|
| 201 | "paymentmethodid" =>$this->paymentList, |
|---|
| 202 | "discountid" =>$this->discountList, |
|---|
| 203 | "salesmanagerid" =>$this->userList |
|---|
| 204 | ); |
|---|
| 205 | $this->updateFields("clients", $clientArray); |
|---|
| 206 | |
|---|
| 207 | $this->updateFields("lineitems", array("productid"=>$this->productsList)); |
|---|
| 208 | $this->updateFields("invoicestatuses", array("defaultassignedtoid"=>$this->userList)); |
|---|
| 209 | $this->updateFields("invoicestatushistory", array("invoiceid"=>$this->invoiceList, "invoicestatusid"=>$this->invoiceStatusList, "assignedtoid"=>$this->userList)); |
|---|
| 210 | $this->updateFields("addresstorecord", array("tabledefid"=>$this->tabledefList, "recordid"=>$this->clientList, "addressid"=>$this->addressList)); |
|---|
| 211 | $this->updateFields("receiptitems", array("receiptid"=>$this->receiptList, "aritemid"=>$this->aritemList)); |
|---|
| 212 | $this->updateFields("receipts", array("clientid"=>$this->clientList, "paymentmethodid"=>$this->paymentList)); |
|---|
| 213 | $this->updateFields("aritems", array("clientid"=>$this->clientList)); |
|---|
| 214 | $this->updateFields("prerequisites", array("parentid"=>$this->productList, "childid"=>$this->productList)); |
|---|
| 215 | |
|---|
| 216 | //we would have to run this if their were addresses associated with other records |
|---|
| 217 | //$this->updateVariableUUIDs("addresstorecord", "tabledefid", "recordid"); |
|---|
| 218 | |
|---|
| 219 | $this->updateAritems(); // need receipt list to work |
|---|
| 220 | $this->updateBMSSettings(); |
|---|
| 221 | |
|---|
| 222 | }//endif |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | //Updates that need to be done after all the other updates |
|---|
| 226 | // Notes attachedtoid |
|---|
| 227 | // attachments |
|---|
| 228 | // addresstorecord |
|---|
| 229 | // AR?? |
|---|
| 230 | // |
|---|
| 231 | // ====== |
|---|
| 232 | // This stuff probably won't be needed as they will be done during the update |
|---|
| 233 | $this->updateVariableUUIDs("notes", "attachedtabledefid", "attachedid"); |
|---|
| 234 | $this->updateVariableUUIDs("attachments", "tabledefid", "recordid"); |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | //Finally add unique indexes to all uuid fields |
|---|
| 238 | $this->addUUIDIndexes(); |
|---|
| 239 | |
|---|
| 240 | return $this->returnJSON(true, "UUID's Generated"); |
|---|
| 241 | |
|---|
| 242 | }//endfunction process |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | function generateUUIDList($table, $whereclause = ""){ |
|---|
| 246 | |
|---|
| 247 | $querystatement = " |
|---|
| 248 | SELECT |
|---|
| 249 | `id`, |
|---|
| 250 | `uuid` |
|---|
| 251 | FROM |
|---|
| 252 | `".$table."`"; |
|---|
| 253 | |
|---|
| 254 | if($whereclause) |
|---|
| 255 | $querystatement .= " |
|---|
| 256 | WHERE ".$whereclause; |
|---|
| 257 | |
|---|
| 258 | $queryresult = $this->db->query($querystatement); |
|---|
| 259 | |
|---|
| 260 | $list = array(); |
|---|
| 261 | while($therecord = $this->db->fetchArray($queryresult)) |
|---|
| 262 | if($therecord["uuid"]) |
|---|
| 263 | $list[$therecord["id"]] = $therecord["uuid"]; |
|---|
| 264 | |
|---|
| 265 | return $list; |
|---|
| 266 | |
|---|
| 267 | }//end function generateUUDIList |
|---|
| 268 | |
|---|
| 269 | /** |
|---|
| 270 | * function updateFields |
|---|
| 271 | * @param string $table |
|---|
| 272 | * @param array $fields An associative array (with fieldnames as keys) |
|---|
| 273 | * of arrays of ids to uuids (generated by $this->generateUUIDList). |
|---|
| 274 | * @example $this->updateFields("reports", array("roleid"=>$this->roleList, "tabledefid"=>$this->tabledefList)); |
|---|
| 275 | */ |
|---|
| 276 | function updateFields($table, $fields){ |
|---|
| 277 | |
|---|
| 278 | $fieldClause ="`id` "; |
|---|
| 279 | |
|---|
| 280 | foreach($fields as $key=>$value) |
|---|
| 281 | $fieldClause .= ", `".$key."`"; |
|---|
| 282 | |
|---|
| 283 | $querystatement = " |
|---|
| 284 | SELECT |
|---|
| 285 | ".$fieldClause." |
|---|
| 286 | FROM |
|---|
| 287 | `".$table."`"; |
|---|
| 288 | |
|---|
| 289 | $queryresult = $this->db->query($querystatement); |
|---|
| 290 | |
|---|
| 291 | $initialClause = ""; |
|---|
| 292 | |
|---|
| 293 | $tablestatement = " |
|---|
| 294 | SHOW FIELDS FROM |
|---|
| 295 | `".$table."` |
|---|
| 296 | WHERE |
|---|
| 297 | `field` = 'stamp' |
|---|
| 298 | OR |
|---|
| 299 | `field` = 'modifieddate' |
|---|
| 300 | "; |
|---|
| 301 | |
|---|
| 302 | $tableresult = $this->db->query($tablestatement); |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | while($tablerecord = $this->db->fetchArray($tableresult)) |
|---|
| 306 | switch($tablerecord["Field"]){ |
|---|
| 307 | |
|---|
| 308 | case "modifieddate": |
|---|
| 309 | case "stamp": |
|---|
| 310 | $initialClause .= ", `".$tablerecord["Field"]."` = `".$tablerecord["Field"]."`"; |
|---|
| 311 | break; |
|---|
| 312 | |
|---|
| 313 | default: |
|---|
| 314 | break; |
|---|
| 315 | }//end switch |
|---|
| 316 | |
|---|
| 317 | while($therecord = $this->db->fetchArray($queryresult)){ |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | $updateClause = $initialClause; |
|---|
| 321 | |
|---|
| 322 | foreach($fields as $key=>$value) |
|---|
| 323 | if(strpos($therecord[$key],":") === false) |
|---|
| 324 | if(isset($value[$therecord[$key]])) |
|---|
| 325 | $updateClause .= ", `".$key."` = '".$value[$therecord[$key]]."'"; |
|---|
| 326 | else |
|---|
| 327 | $updateClause .= ", `".$key."` = ''"; |
|---|
| 328 | |
|---|
| 329 | if($updateClause){ |
|---|
| 330 | |
|---|
| 331 | $updateClause = substr($updateClause, 1); |
|---|
| 332 | |
|---|
| 333 | $updatestatement = " |
|---|
| 334 | UPDATE |
|---|
| 335 | `".$table."` |
|---|
| 336 | SET |
|---|
| 337 | $updateClause |
|---|
| 338 | WHERE |
|---|
| 339 | `id` = ".$therecord["id"]." |
|---|
| 340 | "; |
|---|
| 341 | |
|---|
| 342 | $this->db->query($updatestatement); |
|---|
| 343 | |
|---|
| 344 | }//endif |
|---|
| 345 | |
|---|
| 346 | }//endwhile |
|---|
| 347 | |
|---|
| 348 | }//end function updateField |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | /** |
|---|
| 352 | * function creatUUIDs |
|---|
| 353 | * |
|---|
| 354 | * Gives randomly created uuids to a table with $tabledefuuid (keeping |
|---|
| 355 | * the prefix in the tabledef consistent). |
|---|
| 356 | * |
|---|
| 357 | * @param string $tabledefuuid |
|---|
| 358 | */ |
|---|
| 359 | |
|---|
| 360 | function createUUIDs($tabledefuuid){ |
|---|
| 361 | |
|---|
| 362 | $querystatement = " |
|---|
| 363 | SELECT |
|---|
| 364 | prefix, |
|---|
| 365 | maintable |
|---|
| 366 | FROM |
|---|
| 367 | tabledefs |
|---|
| 368 | WHERE |
|---|
| 369 | uuid = '".$tabledefuuid."'"; |
|---|
| 370 | |
|---|
| 371 | $queryresult = $this->db->query($querystatement); |
|---|
| 372 | |
|---|
| 373 | $therecord = $this->db->fetchArray($queryresult); |
|---|
| 374 | |
|---|
| 375 | $prefix = $therecord["prefix"].":"; |
|---|
| 376 | $tablename = $therecord["maintable"]; |
|---|
| 377 | |
|---|
| 378 | $querystatement = " |
|---|
| 379 | SELECT |
|---|
| 380 | id, |
|---|
| 381 | uuid |
|---|
| 382 | FROM |
|---|
| 383 | `".$tablename."`"; |
|---|
| 384 | |
|---|
| 385 | $queryresult = $this->db->query($querystatement); |
|---|
| 386 | |
|---|
| 387 | while($therecord = $this->db->fetchArray($queryresult)) |
|---|
| 388 | if(strpos($therecord["uuid"], ":") === false){ |
|---|
| 389 | |
|---|
| 390 | $updatestatement = " |
|---|
| 391 | UPDATE |
|---|
| 392 | `".$tablename."` |
|---|
| 393 | SET |
|---|
| 394 | uuid = '".uuid($prefix)."' |
|---|
| 395 | WHERE |
|---|
| 396 | id = ".$therecord["id"]; |
|---|
| 397 | |
|---|
| 398 | $this->db->query($updatestatement); |
|---|
| 399 | |
|---|
| 400 | }//endif //endwhile |
|---|
| 401 | |
|---|
| 402 | }//end function createUUIDs |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | function updateMenuLinks(){ |
|---|
| 406 | |
|---|
| 407 | $querystatement = " |
|---|
| 408 | SELECT |
|---|
| 409 | `id`, |
|---|
| 410 | `link` |
|---|
| 411 | FROM |
|---|
| 412 | `menu` |
|---|
| 413 | WHERE |
|---|
| 414 | `link` LIKE 'search.php?id=%'"; |
|---|
| 415 | |
|---|
| 416 | $queryresult = $this->db->query($querystatement); |
|---|
| 417 | |
|---|
| 418 | while($therecord = $this->db->fetchArray($queryresult)){ |
|---|
| 419 | |
|---|
| 420 | if(preg_match("/search.php\?id\=\d+/", $therecord["link"])){ |
|---|
| 421 | |
|---|
| 422 | $id = substr($therecord["link"], 14); |
|---|
| 423 | |
|---|
| 424 | $updatestatement = " |
|---|
| 425 | UPDATE |
|---|
| 426 | `menu` |
|---|
| 427 | SET |
|---|
| 428 | `link` = 'search.php?id=".urlencode($this->tabledefList[$id])."' |
|---|
| 429 | WHERE |
|---|
| 430 | `id` = ".$therecord["id"]; |
|---|
| 431 | |
|---|
| 432 | $this->db->query($updatestatement); |
|---|
| 433 | |
|---|
| 434 | }//end if |
|---|
| 435 | |
|---|
| 436 | }//endwhile |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | }//end function updateMenuLinks |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | /** |
|---|
| 443 | * function updateAritems |
|---|
| 444 | */ |
|---|
| 445 | |
|---|
| 446 | function updateAritems() { |
|---|
| 447 | |
|---|
| 448 | $querystatment = " |
|---|
| 449 | SELECT |
|---|
| 450 | `type`, |
|---|
| 451 | `relatedid` |
|---|
| 452 | FROM |
|---|
| 453 | `aritems` |
|---|
| 454 | GROUP BY |
|---|
| 455 | `type`, |
|---|
| 456 | `relatedid` |
|---|
| 457 | "; |
|---|
| 458 | |
|---|
| 459 | $queryresult = $this->db->query($querystatment); |
|---|
| 460 | |
|---|
| 461 | while($therecord = $this->db->fetchArray($queryresult)){ |
|---|
| 462 | |
|---|
| 463 | switch($therecord["type"]){ |
|---|
| 464 | |
|---|
| 465 | case "credit": |
|---|
| 466 | $oldRelatedid = $therecord["relatedid"]; |
|---|
| 467 | $updatestatement = " |
|---|
| 468 | UPDATE |
|---|
| 469 | `aritems` |
|---|
| 470 | SET |
|---|
| 471 | `relatedid`='".$this->receiptList[$oldRelatedid]."' |
|---|
| 472 | WHERE |
|---|
| 473 | `relatedid` = '".$oldRelatedid."' |
|---|
| 474 | AND |
|---|
| 475 | `type`='credit' |
|---|
| 476 | "; |
|---|
| 477 | |
|---|
| 478 | $this->db->query($updatestatement); |
|---|
| 479 | break; |
|---|
| 480 | |
|---|
| 481 | default: |
|---|
| 482 | $oldRelatedid = $therecord["relatedid"]; |
|---|
| 483 | |
|---|
| 484 | $updatestatement = " |
|---|
| 485 | UPDATE |
|---|
| 486 | `aritems` |
|---|
| 487 | SET |
|---|
| 488 | `relatedid`='".$this->invoiceList[$oldRelatedid]."' |
|---|
| 489 | WHERE |
|---|
| 490 | `relatedid` = '".$oldRelatedid."' |
|---|
| 491 | AND |
|---|
| 492 | `type`!='credit' |
|---|
| 493 | "; |
|---|
| 494 | |
|---|
| 495 | $this->db->query($updatestatement); |
|---|
| 496 | break; |
|---|
| 497 | |
|---|
| 498 | }//end switch |
|---|
| 499 | |
|---|
| 500 | }//end if |
|---|
| 501 | |
|---|
| 502 | }//end method |
|---|
| 503 | |
|---|
| 504 | /** |
|---|
| 505 | * Updates specific settings that reference ids |
|---|
| 506 | * |
|---|
| 507 | */ |
|---|
| 508 | function updateBMSSettings(){ |
|---|
| 509 | |
|---|
| 510 | $querystatement = " |
|---|
| 511 | SELECT |
|---|
| 512 | * |
|---|
| 513 | FROM |
|---|
| 514 | `settings` |
|---|
| 515 | WHERE |
|---|
| 516 | `name` = 'default_payment' |
|---|
| 517 | OR `name` = 'default_shipping' |
|---|
| 518 | OR `name` = 'default_discount' |
|---|
| 519 | OR `name` = 'default_taxarea'"; |
|---|
| 520 | |
|---|
| 521 | $queryresult = $this->db->query($querystatement); |
|---|
| 522 | |
|---|
| 523 | while($therecord = $this->db->fetchArray($queryresult)){ |
|---|
| 524 | |
|---|
| 525 | $updatestatement = " |
|---|
| 526 | UPDATE |
|---|
| 527 | `settings` |
|---|
| 528 | SET |
|---|
| 529 | `value` = '"; |
|---|
| 530 | if($therecord["value"] != 0) |
|---|
| 531 | switch($therecord["name"]){ |
|---|
| 532 | |
|---|
| 533 | case "default_payment": |
|---|
| 534 | $updatestatement.=$this->paymentList[$therecord["value"]]; |
|---|
| 535 | break; |
|---|
| 536 | |
|---|
| 537 | case "default_shipping": |
|---|
| 538 | $updatestatement.=$this->shippingList[$therecord["value"]]; |
|---|
| 539 | break; |
|---|
| 540 | |
|---|
| 541 | case "default_discount": |
|---|
| 542 | $updatestatement.=$this->discountList[$therecord["value"]]; |
|---|
| 543 | break; |
|---|
| 544 | |
|---|
| 545 | case "default_taxarea": |
|---|
| 546 | $updatestatement.=$this->taxList[$therecord["value"]]; |
|---|
| 547 | break; |
|---|
| 548 | |
|---|
| 549 | }//endswitch |
|---|
| 550 | |
|---|
| 551 | $updatestatement .= "' |
|---|
| 552 | WHERE |
|---|
| 553 | `name` ='".$therecord["name"]."'"; |
|---|
| 554 | |
|---|
| 555 | $this->db->query($updatestatement); |
|---|
| 556 | |
|---|
| 557 | }//endwhile |
|---|
| 558 | |
|---|
| 559 | }//end function updateBMSSettings |
|---|
| 560 | |
|---|
| 561 | /** |
|---|
| 562 | * Updates records that have variable uuid record fields (such as notes attached to and addresses) |
|---|
| 563 | * |
|---|
| 564 | * @param string $tablename name of the table to update |
|---|
| 565 | * @param string $tabledeffield name of the field that holds the tabledef uuid reference |
|---|
| 566 | * @param string $recordfield name of the field that holds the record uuid |
|---|
| 567 | */ |
|---|
| 568 | function updateVariableUUIDs($tablename, $tabledeffield, $recordfield){ |
|---|
| 569 | |
|---|
| 570 | $querystatement = " |
|---|
| 571 | SELECT |
|---|
| 572 | `".$tablename."`.`id`, |
|---|
| 573 | tabledefs.maintable, |
|---|
| 574 | `".$tablename."`.`".$tabledeffield."`, |
|---|
| 575 | `".$tablename."`.`".$recordfield."` |
|---|
| 576 | FROM |
|---|
| 577 | `".$tablename."` INNER JOIN tabledefs ON `".$tablename."`.`".$tabledeffield."` = tabledefs.uuid |
|---|
| 578 | ORDER BY |
|---|
| 579 | `".$tablename."`.`".$tabledeffield."`"; |
|---|
| 580 | |
|---|
| 581 | $queryresult = $this->db->query($querystatement); |
|---|
| 582 | |
|---|
| 583 | $currentTabledefID = NULL; |
|---|
| 584 | |
|---|
| 585 | while($therecord = $this->db->fetchArray($queryresult)){ |
|---|
| 586 | |
|---|
| 587 | if($currentTabledefID !== $therecord[$tabledeffield]){ |
|---|
| 588 | |
|---|
| 589 | switch($therecord[$tabledeffield]){ |
|---|
| 590 | |
|---|
| 591 | case "tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083": //clients: |
|---|
| 592 | $theList = $this->clientList; |
|---|
| 593 | break; |
|---|
| 594 | |
|---|
| 595 | case "tbld:7a9e87ed-d165-c4a4-d9b9-0a4adc3c5a34": //products: |
|---|
| 596 | $theList = $this->productsList; |
|---|
| 597 | break; |
|---|
| 598 | |
|---|
| 599 | case "tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883": //invoices: |
|---|
| 600 | $theList = $this->invoiceList; |
|---|
| 601 | break; |
|---|
| 602 | |
|---|
| 603 | //no list exists, so let's generate it |
|---|
| 604 | default: |
|---|
| 605 | $thelist = $this->generateUUIDList($therecord["maintable"]); |
|---|
| 606 | |
|---|
| 607 | }//endswitch |
|---|
| 608 | |
|---|
| 609 | $currentTabledefID = $therecord[$tabledeffield]; |
|---|
| 610 | |
|---|
| 611 | }//endif |
|---|
| 612 | |
|---|
| 613 | $updatestatement = " |
|---|
| 614 | UPDATE |
|---|
| 615 | `".$tablename."` |
|---|
| 616 | SET |
|---|
| 617 | `".$recordfield."` = '".$theList[$therecord[$recordfield]]."' |
|---|
| 618 | WHERE |
|---|
| 619 | `id` = ".$therecord["id"]; |
|---|
| 620 | |
|---|
| 621 | $this->db->query($updatestatement); |
|---|
| 622 | |
|---|
| 623 | }//endwhile |
|---|
| 624 | |
|---|
| 625 | }//end function updateVariableUUIDs |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | function addUUIDIndexes(){ |
|---|
| 629 | |
|---|
| 630 | $querystatement = "SHOW TABLES"; |
|---|
| 631 | |
|---|
| 632 | $queryresult = $this->db->query($querystatement); |
|---|
| 633 | |
|---|
| 634 | while($therecord = $this->db->fetchArray($queryresult)){ |
|---|
| 635 | |
|---|
| 636 | $tablename = array_pop($therecord); |
|---|
| 637 | |
|---|
| 638 | $querystatement = "DESCRIBE `".$tablename."`"; |
|---|
| 639 | |
|---|
| 640 | $columnsresult = $this->db->query($querystatement); |
|---|
| 641 | |
|---|
| 642 | $hasUUID = false; |
|---|
| 643 | |
|---|
| 644 | while($columnrecord = $this->db->fetchArray($columnsresult)){ |
|---|
| 645 | |
|---|
| 646 | if($columnrecord["Field"] == "uuid"){ |
|---|
| 647 | |
|---|
| 648 | $hasUUID = true; |
|---|
| 649 | break; |
|---|
| 650 | |
|---|
| 651 | }//endif |
|---|
| 652 | |
|---|
| 653 | }//endwhile |
|---|
| 654 | |
|---|
| 655 | if($hasUUID){ |
|---|
| 656 | |
|---|
| 657 | $alterstatement = "ALTER TABLE `".$tablename."` ADD UNIQUE (`uuid`)"; |
|---|
| 658 | |
|---|
| 659 | $this->db->query($alterstatement); |
|---|
| 660 | |
|---|
| 661 | }//endif |
|---|
| 662 | |
|---|
| 663 | }//endwhile |
|---|
| 664 | |
|---|
| 665 | }// end function addUUIDIndexes |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | }//end class updateAjax |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | // START PROCESSING |
|---|
| 672 | //============================================================================== |
|---|
| 673 | |
|---|
| 674 | if(!isset($noOutput)){ |
|---|
| 675 | $genUUIDS = new generateUUIDS(); |
|---|
| 676 | echo $genUUIDS->process(); |
|---|
| 677 | }//end if |
|---|