示例#1
0
 public function copyResourcesFolder($type = 'site', $overWrite = true)
 {
     // Get theme path
     $path = Yii::getPathOfAlias('themes.' . $type) . '/www';
     $dest = Yii::getPathOfAlias('themes.' . $this->dirname . '/www');
     $files = $this->getResourcesFiles($type);
     foreach ($files as $key => $file) {
         $source = $file;
         $file = str_replace($this->getSourceWwwDir($type), '', $file);
         $inserts[] = array('file_name' => end(explode('/', $file)), 'file_location' => '/www' . $file, 'file_directory' => 'www/' . trim(str_replace(array('/www', end(explode('/', $file))), '', $file), '/'), 'file_ext' => end(explode('.', $file)), 'content' => file_get_contents($source));
     }
     foreach ($inserts as $insert) {
         // Check if the file location exists
         $exists = ThemeFile::model()->exists('theme_id=:id AND file_location=:location', array(':id' => $this->id, ':location' => $insert['file_location']));
         if (!$exists) {
             // Add to the db
             $themeFile = new ThemeFile();
             $themeFile->theme_id = $this->id;
             $themeFile->file_name = $insert['file_name'];
             $themeFile->file_location = $insert['file_location'];
             $themeFile->file_directory = $insert['file_directory'];
             $themeFile->file_ext = $insert['file_ext'];
             $themeFile->content = $insert['content'];
             $themeFile->save(false);
         }
     }
     if ($path) {
         // We copy themes/$type/www to the new theme location
         return copyr($path, $dest, $overWrite);
     }
     return false;
 }