Created
April 3, 2014 13:43
-
-
Save putzflorian/9954594 to your computer and use it in GitHub Desktop.
Import Redirects in Pimcore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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