Skip to content

Instantly share code, notes, and snippets.

@putzflorian
Created April 3, 2014 13:43
Show Gist options
  • Select an option

  • Save putzflorian/9954594 to your computer and use it in GitHub Desktop.

Select an option

Save putzflorian/9954594 to your computer and use it in GitHub Desktop.
Import Redirects in Pimcore
<?php
$today = new Zend_Date();
$today->add(6, Zend_Date::MONTH);
$time = $today->getTimestamp();
$rd = new InsertRedirect();
$row = 1;
if (($handle = fopen("redirects.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 10000, ";")) !== FALSE) {
$num = count($data);
$rd->insert($data[0], $data[1], $time);
echo 'add: ' . $data[0] . ' --> ' . $data[1] . "\n";
if($row % 12==10){
Pimcore::collectGarbage();
}
$row++;
}
fclose($handle);
}
class InsertRedirect {
public function insert($source, $target, $expiry){
$data = new Redirect();
$data->setSource('@^' . preg_quote($source, '@') . '$@');
$data->setTarget($target);
$data->setExpiry($expiry);
$data->save();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment