Permalink
Browse files

fixed `li3 couchbase import` to use fewer iterators

  • Loading branch information...
1 parent 67077cb commit a6d739c7bb6af5e6b433985bc693add0f22f8f2a @phishy phishy committed Feb 13, 2013
Showing with 9 additions and 14 deletions.
  1. +9 −14 extensions/command/Couchbase.php
@@ -32,23 +32,18 @@ public function _init() {
/**
* Loads design docs into Couchbase
*
- * @todo Fix Iterator mess. I'm pretty sure I've done it wrong in my haste.
*/
public function import() {
$data = array();
- $dir = new \RecursiveDirectoryIterator($this->viewPath);
- foreach ($dir as $fileinfo) {
- if ($fileinfo->isDir()) {
- $viewDir = new \RecursiveDirectoryIterator($fileinfo->getPathname());
- foreach ($viewDir as $fi) {
- $scripts = new \RecursiveDirectoryIterator($fi->getPathName());
- foreach ($scripts as $f) {
- $fn = str_replace('.js', '', $f->getFilename());
- $data[$fileinfo->getFilename()]['views'][$fi->getFilename()][$fn] =
- file_get_contents($f->getPathname());
- }
- }
-
+ $dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->viewPath));
+ foreach ($dir as $k => $v) {
+ if (!in_array($v->getFilename(), array('.', '..'))) {
+ $pieces = explode('/', $k);
+ $file = array_pop($pieces);
+ $view = array_pop($pieces);
+ $design = array_pop($pieces);
+ $file = str_replace('.js', '', $file);
+ $data[$design]['views'][$view][$file] = file_get_contents($v->getPathname());
}
}
foreach ($data as $design => $v) {

0 comments on commit a6d739c

Please sign in to comment.