Exemplo n.º 1
0
 /**
  *	Creates a field type definition from the structure of the table in the DB
  *
  *	Generate and save a cache file in the e_CACHE_DB directory,
  *	Also update $this->dbFieldDefs[$tableName] - FALSE if error, data if found
  *
  *	@param	string $tableName - name of table sought
  *
  *	@return boolean TRUE on success, FALSE on not found (some errors intentionally ignored)
  */
 protected function makeTableDef($tableName)
 {
     require_once e_HANDLER . 'db_table_admin_class.php';
     $dbAdm = new db_table_admin();
     $baseStruct = $dbAdm->get_current_table($tableName);
     $fieldDefs = $dbAdm->parse_field_defs($baseStruct[0][2]);
     // Required definitions
     $outDefs = array();
     foreach ($fieldDefs as $k => $v) {
         switch ($v['type']) {
             case 'field':
                 if (vartrue($v['autoinc'])) {
                     //break;		Probably include autoinc fields in array
                 }
                 $baseType = preg_replace('#\\(\\d+?\\)#', '', $v['fieldtype']);
                 // Should strip any length
                 switch ($baseType) {
                     case 'int':
                     case 'shortint':
                     case 'tinyint':
                         $outDefs['_FIELD_TYPES'][$v['name']] = 'int';
                         break;
                     case 'char':
                     case 'text':
                     case 'varchar':
                         $outDefs['_FIELD_TYPES'][$v['name']] = 'escape';
                         //XXX toDB() causes serious BC issues.
                         break;
                 }
                 //	if($v['name'])
                 if (isset($v['nulltype']) && !isset($v['default'])) {
                     $outDefs['_NOTNULL'][$v['name']] = '';
                 }
                 break;
             case 'pkey':
             case 'ukey':
             case 'key':
             case 'ftkey':
                 break;
                 // Do nothing with keys for now
             // Do nothing with keys for now
             default:
                 echo "Unexpected field type: {$k} => {$v['type']}<br />";
         }
     }
     $array = e107::getArrayStorage();
     $this->dbFieldDefs[$tableName] = $outDefs;
     $toSave = $array->WriteArray($outDefs, FALSE);
     // 2nd parameter to TRUE if needs to be written to DB
     if (FALSE === file_put_contents(e_CACHE_DB . $tableName . '.php', $toSave)) {
         // Could do something with error - but mustn't return FALSE - would trigger auto-generated structure
         $mes = e107::getMessage();
         $mes->addDebug("Error writing file: " . e_CACHE_DB . $tableName . '.php');
         //Fix for during v1.x -> 2.x upgrade.
         // echo "Error writing file: ".e_CACHE_DB.$tableName.'.php'.'<br />';
     }
 }
Exemplo n.º 2
0
//						ACTION
//========================================================
if (isset($_POST['do_conversion'])) {
    if (varset($_POST['selected_plugin'], FALSE)) {
        $table = $_POST['selected_plugin'];
        if (!isset($tableArray[$table])) {
            $message = 'Bad table name specified';
            $table = '';
        }
    } else {
        $message = 'No table name specified';
    }
}
if ($table) {
    $baseStruct = $dbAdm->get_table_def($table, $tableArray[$table]['src']);
    $fieldDefs = $dbAdm->parse_field_defs($baseStruct[0][2]);
    // Required definitions
    $outDefs = array();
    foreach ($fieldDefs as $k => $v) {
        switch ($v['type']) {
            case 'field':
                if (vartrue($v['autoinc'])) {
                    if (isset($outDefs['WHERE'])) {
                    } else {
                        $outDefs['WHERE'] = "`{$v['name']}` = \$id";
                    }
                    break;
                }
                $baseType = preg_replace('#\\(\\d+?\\)#', '', $v['fieldtype']);
                // Should strip any length
                switch ($baseType) {