Skip to content

Instantly share code, notes, and snippets.

@ViliamKopecky
Created February 19, 2012 20:18
Show Gist options
  • Save ViliamKopecky/1865565 to your computer and use it in GitHub Desktop.
Save ViliamKopecky/1865565 to your computer and use it in GitHub Desktop.
Migrace
<?php
require_once __DIR__ . '/clevis/Eleda/libs/Nette/loader.php';
require_once __DIR__ . '/clevis/Eleda/libs/dibi/dibi.php';
use Nette\Utils\Strings as Strings;
dibi::connect(array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'eleda1'
));
function updateRow($str) {
$el = '/<element id=\"(?P<id>[\d]*)\" type=\"(?P<type>[\d]*)\" (class="gap" |class="bubble" )?(description|title)=\"(?P<description>[^"]*)\">(?P<text>[^<]*)<\/element>/ui';
$new = Strings::replace($str, $el, function($m){
$id = $m['id'];
$class = ($m['type'] === "1") ? "gap" : "bubble";
$title = $m['description'];
$text = $m['text'];
$str = '<span id="'
. $id
. '" class="'
. $class
. '" title="'
. $title
. '">'
. $text
. '</span>';
return $str;
});
return $new;
}
$table = 'content_fulltext';
$col = 'content';
$rows = dibi::select('id, content')->from($table)->fetchAll();
foreach($rows as $r) {
if(!empty($r->content)) {
$content = updateRow($r->content);
dibi::update($table, array('content' => $content))->where('id = %i', $r->id)->execute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment