예제 #1
0
 protected function actionUpgrade($params)
 {
     if (!$this->isCli()) {
         echo '<pre>';
     }
     if (!version_compare(phpversion(), "5.3", ">=")) {
         exit("You are running a PHP version older than 5.3. PHP 5.3 or greater is required to run Group-Office " . \GO::config()->version);
     }
     $this->lockAction();
     GO::setIgnoreAclPermissions(true);
     GO::session()->runAsRoot();
     \GO::clearCache();
     \GO\Base\Db\Columns::$forceLoad = true;
     //don't be strict in upgrade process
     \GO::getDbConnection()->query("SET sql_mode=''");
     $v3 = $this->_checkV3();
     $logDir = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'log/upgrade/');
     $logDir->create();
     global $logFile;
     $logFile = $logDir->path() . '/' . date('Ymd_Gi') . '.log';
     touch($logFile);
     if (!is_writable($logFile)) {
         die('Fatal error: Could not write to log file');
     }
     ob_start("GO\\Core\\Controller\\MaintenanceController::ob_upgrade_log");
     echo "Updating " . \GO::config()->product_name . " database\n";
     //build an array of all update files. The queries are indexed by timestamp
     //so they will all be executed in the right order.
     $u = array();
     require \GO::config()->root_path . 'install/updates.php';
     //put the updates in an extra array dimension so we know to which module
     //they belong too.
     foreach ($updates as $timestamp => $updatequeries) {
         $u["{$timestamp}"]['core'] = $updatequeries;
     }
     $modules = \GO::modules()->getAllModules();
     while ($module = array_shift($modules)) {
         if ($module->isAvailable()) {
             $updatesFile = $module->path . 'install/updates.php';
             if (!file_exists($updatesFile)) {
                 $updatesFile = $module->path . 'install/updates.inc.php';
             }
             if (file_exists($updatesFile)) {
                 $updates = array();
                 require $updatesFile;
                 //put the updates in an extra array dimension so we know to which module
                 //they belong too.
                 foreach ($updates as $timestamp => $updatequeries) {
                     $u["{$timestamp}"][$module->id] = $updatequeries;
                 }
             }
         }
     }
     //sort the array by timestamp
     ksort($u);
     //
     //		var_dump($u);
     //		exit();
     $currentCoreVersion = \GO::config()->get_setting('version');
     if (!$currentCoreVersion) {
         $currentCoreVersion = 0;
     }
     $counts = array();
     foreach ($u as $timestamp => $updateQuerySet) {
         foreach ($updateQuerySet as $module => $queries) {
             //echo "Getting updates for ".$module."\n";
             if (!is_array($queries)) {
                 exit("Invalid queries in module: " . $module);
             }
             if ($module == 'core') {
                 $currentVersion = $currentCoreVersion;
             } else {
                 $currentVersion = \GO::modules()->{$module}->version;
             }
             if (!isset($counts[$module])) {
                 $counts[$module] = 0;
             }
             foreach ($queries as $query) {
                 $counts[$module]++;
                 if ($counts[$module] > $currentVersion) {
                     if (substr($query, 0, 7) == 'script:') {
                         if ($module == 'core') {
                             $updateScript = \GO::config()->root_path . 'install/updatescripts/' . substr($query, 7);
                         } else {
                             $updateScript = \GO::modules()->{$module}->path . 'install/updatescripts/' . substr($query, 7);
                         }
                         if (!file_exists($updateScript)) {
                             die($updateScript . ' not found!');
                         }
                         //if(!$quiet)
                         echo 'Running ' . $updateScript . "\n";
                         flush();
                         if (empty($params['test'])) {
                             require_once $updateScript;
                         }
                     } else {
                         echo 'Excuting query: ' . $query . "\n";
                         flush();
                         if (empty($params['test'])) {
                             try {
                                 if (!empty($query)) {
                                     \GO::getDbConnection()->query($query);
                                 }
                             } catch (PDOException $e) {
                                 //var_dump($e);
                                 echo $e->getMessage() . "\n";
                                 echo "Query: " . $query;
                                 //									if ($e->getCode() == 1091 || $e->getCode() == 1060) {
                                 //										//duplicate and drop errors. Ignore those on updates
                                 //									} else {
                                 //										die();
                                 //									}
                             }
                         }
                     }
                     if (empty($params['test'])) {
                         if ($module == 'core') {
                             \GO::config()->save_setting('version', $counts[$module]);
                         } else {
                             //echo $module.' updated to '.$counts[$module]."\n";
                             $moduleModel = \GO::modules()->{$module};
                             $moduleModel->version = $counts[$module];
                             $moduleModel->save();
                         }
                         ob_flush();
                     }
                 }
             }
         }
     }
     if (empty($params['test'])) {
         echo "Database updated to version " . \GO::config()->mtime, "\n";
         ob_flush();
         \GO::config()->save_setting('upgrade_mtime', \GO::config()->mtime);
     } else {
         echo "Ran in test mode\n";
     }
     echo "Removing cached javascripts...\n\n";
     //in some exceptions alowed deletes is still on false here.
     \GO\Base\Fs\File::setAllowDeletes(true);
     \GO::clearCache();
     //rebuild listeners
     \GO\Base\Observable::cacheListeners();
     if ($v3) {
         //			if(\GO::modules()->isInstalled('projects') && \GO::modules()->isInstalled('files')){
         //				echo "Renaming projects folder temporarily for new project paths\n";
         //				$folder = \GO\Files\Model\Folder::model()->findByPath('projects');
         //				if($folder){
         //					$folder->name='oldprojects';
         //					$folder->systemSave=true;
         //					$folder->save();
         //				}
         //			}
         //			echo "Checking database after version 3.7 upgrade.\n";
         //			$this->actionCheckDatabase($params);
         //			echo "Done\n\n";
         //			ob_flush();
         $versioningFolder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'versioning');
         if ($versioningFolder->exists()) {
             $versioningFolder->rename("versioning_backup_3_7");
         }
         if (!$this->isCli()) {
             echo '</pre>';
         }
         echo "Building search cache after version 3.7 upgrade.\n";
         ob_flush();
         $this->run("buildsearchcache", $params);
         ob_flush();
         if (!$this->isCli()) {
             echo '<pre>';
         }
     }
     echo "All Done!\n";
     if (!$this->isCli() && basename($_SERVER['PHP_SELF']) != 'upgrade.php') {
         echo '</pre><br /><br />';
         echo '<a href="' . \GO::config()->host . '">' . \GO::t('cmdContinue') . '</a>';
     }
     ob_end_flush();
     \GO\Base\Db\Columns::$forceLoad = false;
     //return $response;
 }
예제 #2
0
 protected function actionThumb($params)
 {
     GO::session()->closeWriting();
     $dir = GO::config()->root_path . 'views/Extjs3/themes/Default/images/128x128/filetypes/';
     $url = GO::config()->host . 'views/Extjs3/themes/Default/images/128x128/filetypes/';
     $file = new \GO\Base\Fs\File(GO::config()->file_storage_path . $params['src']);
     if (is_dir(GO::config()->file_storage_path . $params['src'])) {
         $src = $dir . 'folder.png';
     } else {
         switch (strtolower($file->extension())) {
             case 'svg':
             case 'ico':
             case 'jpg':
             case 'jpeg':
             case 'png':
             case 'gif':
             case 'xmind':
                 $src = GO::config()->file_storage_path . $params['src'];
                 break;
             case 'tar':
             case 'tgz':
             case 'gz':
             case 'bz2':
             case 'zip':
                 $src = $dir . 'zip.png';
                 break;
             case 'odt':
             case 'docx':
             case 'doc':
             case 'htm':
             case 'html':
                 $src = $dir . 'doc.png';
                 break;
             case 'odc':
             case 'ods':
             case 'xls':
             case 'xlsx':
                 $src = $dir . 'spreadsheet.png';
                 break;
             case 'odp':
             case 'pps':
             case 'pptx':
             case 'ppt':
                 $src = $dir . 'pps.png';
                 break;
             case 'eml':
                 $src = $dir . 'message.png';
                 break;
             case 'log':
                 $src = $dir . 'txt.png';
                 break;
             default:
                 if (file_exists($dir . $file->extension() . '.png')) {
                     $src = $dir . $file->extension() . '.png';
                 } else {
                     $src = $dir . 'unknown.png';
                 }
                 break;
         }
     }
     $file = new \GO\Base\Fs\File($src);
     if ($file->size() > \GO::config()->max_thumbnail_size * 1024 * 1024) {
         throw new \Exception("Image may not be larger than 5MB.");
     }
     $w = isset($params['w']) ? intval($params['w']) : 0;
     $h = isset($params['h']) ? intval($params['h']) : 0;
     $zc = !empty($params['zc']) && !empty($w) && !empty($h);
     $lw = isset($params['lw']) ? intval($params['lw']) : 0;
     $lh = isset($params['lh']) ? intval($params['lh']) : 0;
     $pw = isset($params['pw']) ? intval($params['pw']) : 0;
     $ph = isset($params['ph']) ? intval($params['ph']) : 0;
     if ($file->extension() == 'xmind') {
         //			$filename = $file->nameWithoutExtension().'.jpeg';
         //
         //			if (!file_exists($GLOBALS['GO_CONFIG']->file_storage_path . 'thumbcache/' . $filename) || filectime($GLOBALS['GO_CONFIG']->file_storage_path . 'thumbcache/' . $filename) < filectime($GLOBALS['GO_CONFIG']->file_storage_path . $path)) {
         //				$zipfile = zip_open($GLOBALS['GO_CONFIG']->file_storage_path . $path);
         //
         //				while ($entry = zip_read($zipfile)) {
         //					if (zip_entry_name($entry) == 'Thumbnails/thumbnail.jpg') {
         //						require_once($GLOBALS['GO_CONFIG']->class_path . 'filesystem.class.inc');
         //						zip_entry_open($zipfile, $entry, 'r');
         //						file_put_contents($GLOBALS['GO_CONFIG']->file_storage_path . 'thumbcache/' . $filename, zip_entry_read($entry, zip_entry_filesize($entry)));
         //						zip_entry_close($entry);
         //						break;
         //					}
         //				}
         //				zip_close($zipfile);
         //			}
         //			$path = 'thumbcache/' . $filename;
     }
     $cacheDir = new \GO\Base\Fs\Folder(GO::config()->orig_tmpdir . 'thumbcache');
     $cacheDir->create();
     $cacheFilename = str_replace(array('/', '\\'), '_', $file->parent()->path() . '_' . $w . '_' . $h . '_' . $lw . '_' . $ph . '_' . '_' . $pw . '_' . $lw);
     if ($zc) {
         $cacheFilename .= '_zc';
     }
     //$cache_filename .= '_'.filesize($full_path);
     $cacheFilename .= $file->name();
     $readfile = $cacheDir->path() . '/' . $cacheFilename;
     $thumbExists = file_exists($cacheDir->path() . '/' . $cacheFilename);
     $thumbMtime = $thumbExists ? filemtime($cacheDir->path() . '/' . $cacheFilename) : 0;
     GO::debug("Thumb mtime: " . $thumbMtime . " (" . $cacheFilename . ")");
     if (!empty($params['nocache']) || !$thumbExists || $thumbMtime < $file->mtime() || $thumbMtime < $file->ctime()) {
         GO::debug("Resizing image");
         $image = new \GO\Base\Util\Image($file->path());
         if (!$image->load_success) {
             GO::debug("Failed to load image for thumbnailing");
             //failed. Stream original image
             $readfile = $file->path();
         } else {
             if ($zc) {
                 $image->zoomcrop($w, $h);
             } else {
                 if ($lw || $lh || $pw || $lw) {
                     //treat landscape and portrait differently
                     $landscape = $image->landscape();
                     if ($landscape) {
                         $w = $lw;
                         $h = $lh;
                     } else {
                         $w = $pw;
                         $h = $ph;
                     }
                 }
                 GO::debug($w . "x" . $h);
                 if ($w && $h) {
                     $image->resize($w, $h);
                 } elseif ($w) {
                     $image->resizeToWidth($w);
                 } else {
                     $image->resizeToHeight($h);
                 }
             }
             $image->save($cacheDir->path() . '/' . $cacheFilename);
         }
     }
     header("Expires: " . date("D, j M Y G:i:s ", time() + 86400 * 365) . 'GMT');
     //expires in 1 year
     header('Cache-Control: cache');
     header('Pragma: cache');
     header('Content-Type: ' . $file->mimeType());
     header('Content-Disposition: inline; filename="' . $cacheFilename . '"');
     header('Content-Transfer-Encoding: binary');
     readfile($readfile);
     //			case 'pdf':
     //				$this->redirect($url . 'pdf.png');
     //				break;
     //
     //			case 'tar':
     //			case 'tgz':
     //			case 'gz':
     //			case 'bz2':
     //			case 'zip':
     //				$this->redirect( $url . 'zip.png');
     //				break;
     //			case 'odt':
     //			case 'docx':
     //			case 'doc':
     //				$this->redirect( $url . 'doc.png');
     //				break;
     //
     //			case 'odc':
     //			case 'ods':
     //			case 'xls':
     //			case 'xlsx':
     //				$this->redirect( $url . 'spreadsheet.png');
     //				break;
     //
     //			case 'odp':
     //			case 'pps':
     //			case 'pptx':
     //			case 'ppt':
     //				$this->redirect( $url . 'pps.png');
     //				break;
     //			case 'eml':
     //				$this->redirect( $url . 'message.png');
     //				break;
     //
     //			case 'htm':
     //				$this->redirect( $url . 'doc.png');
     //				break;
     //
     //			case 'log':
     //				$this->redirect( $url . 'txt.png');
     //				break;
     //
     //			default:
     //				if (file_exists($dir . $file->extension() . '.png')) {
     //					$this->redirect( $url . $file->extension() . '.png');
     //				} else {
     //					$this->redirect( $url . 'unknown.png');
     //				}
     //				break;
 }