Changeset 1546

Show
Ignore:
Timestamp:
08/24/06 20:51:31 (2 years ago)
Author:
mbonetti
Message:

experimental: XML dump of the installation.

Location:
trunk/gregarius
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/gregarius/admin/channels.php

    r1542 r1546  
    741741        break; 
    742742 
    743  
     743    case 'dump': 
     744        // Make sure this is a POST 
     745        if(!isset($_POST['dumpact'])) { 
     746            die('Sorry, you can\'t access this via a GET'); 
     747        } 
     748        $tbl = array('"','"'); 
     749        error_reporting(E_ALL); 
     750        rss_require('schema.php'); 
     751        $tables=getExpectedTables(); 
     752        unset($tables['cache']); 
     753        //$tables=array('channels','tag','config'); 
     754        $bfr=''; 
     755        $bfr .= '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'."\n"; 
     756        $bfr .= '<dump prefix="'.getTable('').'" date="'.date('r').'">'."\n"; 
     757        foreach($tables as $table => $prefixed) { 
     758            $rs = rss_query("select * from $prefixed"); 
     759            $bfr .="<$table>\n"; 
     760            while($row=rss_fetch_assoc($rs)) { 
     761                $r="<row "; 
     762                foreach($row as $key => $val) { 
     763                    $val=htmlspecialchars($val); 
     764                    $r.=" $key=\"$val\" "; 
     765                } 
     766                $r .= "/>\n"; 
     767                $bfr .=$r; 
     768            } 
     769            $bfr .="</$table>\n"; 
     770        } 
     771        $bfr .='</dump>'."\n"; 
     772        $gzdata = gzencode($bfr, 9); 
     773        $tempfname=tempnam("/tmp", "rss.dump").'.xml.gz'; 
     774        $df=fopen($tempfname,'w'); 
     775        fwrite($df, $gzdata); 
     776        fclose($df); 
     777        die($tempfname); 
     778        break; 
    744779    default: 
    745780        break; 
  • trunk/gregarius/admin/opml.php

    r1528 r1546  
    9191    // export 
    9292    opml_export_form(); 
    93  
     93    dump_export_form(); 
    9494    echo "</div>\n"; 
    9595} 
     
    113113} 
    114114 
     115 
     116/***** DUMP ******/ 
     117 
     118function dump_export_form() { 
     119 
     120    echo "<fieldset style=\"vertical-align:top\">\n<legend>".__('XML Dump:')."</legend>\n"; 
     121    echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">\n" 
     122    ."<p><label for=\"action\">". __('Dump your Gregarius installation to XML'). "</label>\n" 
     123    ."<input type=\"submit\" name=\"dumpact\" id=\"action\" value=\"".__('Dump!')."\" />" 
     124    ."<input type=\"hidden\" name=\"". CST_ADMIN_DOMAIN ."\" value=\"".CST_ADMIN_DOMAIN_CHANNEL."\"/>\n" 
     125    ."<input type=\"hidden\" name=\"".CST_ADMIN_METAACTION."\" value=\"dump\"/>\n" 
     126    ."</p>\n</form>\n" 
     127    ."</fieldset>\n"; 
     128} 
     129 
    115130?> 
  • trunk/gregarius/ajax.php

    r1525 r1546  
    215215      toggle.innerHTML="<?php echo  LBL_TAG_SUBMITTING ?>"; 
    216216        submit_tag(id,fld.value); 
    217     } else if (toggle.innerHTML == "<?php echo  LBL_TAG_EDIT ?>") { 
     217    } else if (toggle.innerHTML == "<?php echo LBL_TAG_EDIT ?>") { 
    218218       var isIE=document.all?true:false; 
    219219       // the tag container 
  • trunk/gregarius/schema.php

    r1520 r1546  
    3838    $missing_tables = array(); 
    3939    $actual_tables=array(); 
    40     $expected_tables = array ( 
     40    $expected_tables = getExpectedTables(); 
     41     
     42    $rs = rss_query( "show tables", true, true ); 
     43    while(list($tbl) = rss_fetch_row($rs)) { 
     44        $actual_tables[]=$tbl; 
     45    } 
     46     
     47    foreach ($expected_tables as $base => $tbl) { 
     48        $exists = array_search($tbl,$actual_tables); 
     49        if ($exists === FALSE || $exists === NULL) { 
     50            $missing_tables[]=$base; 
     51        } 
     52    } 
     53     
     54    $updated  = 0; 
     55    if (count($missing_tables) > 0) { 
     56        $msg = (count($actual_tables)?"Updating":"Creating") 
     57            .' your database schema! This should be a one-time operation,' 
     58            .' if you see this message over and over again please import your database schema' 
     59            .' manually.'; 
     60        rss_error($msg, RSS_ERROR_WARNING); 
     61 
     62        foreach($missing_tables as $table) { 
     63            $updated += call_user_func("_init_$table");  
     64        } 
     65         
     66        if ($updated == count($missing_tables)) { 
     67            rss_error("Successfully created $updated of $updated database tables!", RSS_ERROR_NOTICE); 
     68        } else { 
     69            rss_error( 
     70                (count($missing_tables) - $updated) . " out of " 
     71            . count($missing_tables) ." tables could not be created!",RSS_ERROR_ERROR); 
     72        } 
     73    } 
     74     
     75    if ($updated) { 
     76        rss_invalidate_cache(); 
     77    } 
     78    return $updated; 
     79} 
     80 
     81function getExpectedTables() { 
     82$expected_tables = array ( 
    4183        "channels" => trim(getTable("channels")), 
    4284        "config" => trim(getTable("config")), 
     
    5294 
    5395    ); 
    54      
    55     $rs = rss_query( "show tables", true, true ); 
    56     while(list($tbl) = rss_fetch_row($rs)) { 
    57         $actual_tables[]=$tbl; 
    58     } 
    59      
    60     foreach ($expected_tables as $base => $tbl) { 
    61         $exists = array_search($tbl,$actual_tables); 
    62         if ($exists === FALSE || $exists === NULL) { 
    63             $missing_tables[]=$base; 
    64         } 
    65     } 
    66      
    67     $updated  = 0; 
    68     if (count($missing_tables) > 0) { 
    69         $msg = (count($actual_tables)?"Updating":"Creating") 
    70             .' your database schema! This should be a one-time operation,' 
    71             .' if you see this message over and over again please import your database schema' 
    72             .' manually.'; 
    73         rss_error($msg, RSS_ERROR_WARNING); 
    74  
    75         foreach($missing_tables as $table) { 
    76             $updated += call_user_func("_init_$table");  
    77         } 
    78          
    79         if ($updated == count($missing_tables)) { 
    80             rss_error("Successfully created $updated of $updated database tables!", RSS_ERROR_NOTICE); 
    81         } else { 
    82             rss_error( 
    83                 (count($missing_tables) - $updated) . " out of " 
    84             . count($missing_tables) ." tables could not be created!",RSS_ERROR_ERROR); 
    85         } 
    86     } 
    87      
    88     if ($updated) { 
    89         rss_invalidate_cache(); 
    90     } 
    91     return $updated; 
    92 } 
    93  
     96    return $expected_tables; 
     97} 
    9498function rss_query_wrapper($query, $dieOnError=true, $preventRecursion=false) { 
    9599    global $out;