/** * Method used to populate the cache table in case the form storage mechanism is not DB like * @param boolean $check_mod. Defaults to true. If false, it skips the mod time check */ protected function slowPopulate($check_mod = true, $id = null) { $fields = array(); $mdb2_types = array(); $default_values = array(); foreach ($this->formObj as $field => $fieldObj) { if (!$fieldObj->isInDB()) { continue; } $fields[] = $field; $mdb2_types[] = $fieldObj->getMDB2Type(); $default_values[$field] = $fieldObj->getDBValue(); } $default_values['last_modified'] = '1900-01-01 00:00:00'; $default_values['created'] = '0000-00-00 00:00:00'; $default_values['parent'] = '|'; $insert_fields = $fields; $insert_fields[] = 'last_modified'; $insert_fields[] = 'created'; $fields[] = 'last_modified'; $fields[] = 'created'; $fields[] = 'parent'; $insert_fields[] = 'parent'; $insert_fields[] = "id"; $update_fields = array(); foreach ($insert_fields as &$field) { $field = '`' . $field . '`'; $update_fields[] = "{$field}=values({$field})"; } unset($field); $insertQry = 'INSERT INTO ' . $this->table_name . " (" . implode(',', $insert_fields) . " ) " . " VALUES (" . implode(',', array_fill(0, count($insert_fields), '?')) . ")" . " ON DUPLICATE KEY UPDATE " . implode(',', $update_fields); if (I2CE_CachedForm::$spam) { I2CE::raiseError("Slow populate:\n{$insertQry}"); } $db = MDB2::singleton(); $prep = $db->prepare($insertQry, $mdb2_types, MDB2_PREPARE_MANIP); if (I2CE::pearError($prep, "Error setting up form in the database:")) { return false; } if ($check_mod) { $mod_time = $this->getLastCachedTime(); } else { $mod_time = -1; } $storage = I2CE_FormStorage::getStorageMechanism($this->form); if (!$storage instanceof I2CE_FormStorage_Mechanism) { I2CE::raiseError("form {$form} does not have valid form storage mechanism"); return false; } if (I2CE_CachedForm::$spam) { I2CE::raiseError("Mod Time ={$mod_time}"); } if ($id !== null) { $ids = array($id); } else { $ids = $storage->getRecords($this->form, $mod_time); } if (I2CE_CachedForm::$spam) { I2CE::raiseError(implode("\n", $ids)); } foreach ($ids as $id) { $data = $storage->lookupField($this->form, $id, $fields, false); if (!is_array($data)) { continue; } $t_data = array(); foreach ($fields as $field) { if (array_key_exists($field, $data)) { $t_data[] = $data[$field]; } else { $t_data[] = $default_values[$field]; } } $t_data[] = $this->form . "|" . $id; $res = $prep->execute($t_data); if (I2CE::pearError($res, "Error insert into cache table:")) { return false; } } I2CE_FormStorage::releaseStorage($this->form); if (I2CE_CachedForm::$spam) { I2CE::raiseError("Populated " . count($ids) . " entries for {$this->form}"); } return true; }