<?php
// 更新缓存
class CacheAction extends BaseAction {
	/**
	 * 更新缓存
	 *
	 * @access public
	 * @param void
	 * @return boolean
	 */
	public function defaults() {
		// 清空相关缓存目录
		$dir = JXCMS_ROOT . 'jxcms/Runtime/';
		FileUtil :: del($dir . 'Cache', 1);
		FileUtil :: del($dir . 'Fields', 1);
		FileUtil :: del($dir . 'Templates', 1);
		// 重建缓存
		$t1 = glob(JXCMS_ROOT . 'Lib/Model/*');
		foreach($t1 as $t11) {
			if (!is_dir($t11)) {
				if (substr($t11, -15) == 'Model.class.php') $this -> cache($t11);
			} else {
				$t2 = glob($t11 . '/*Model.class.php');
				foreach($t2 as $t22) $this -> cache($t22);
			}
		}
		$this -> showMsg(L('OPERATE_SUCCESS'));
	}
	/**
	 * 生成缓存
	 *
	 * @access private
	 * @param string $classFile 类文件详细路径
	 */
	private function cache($classFile) {
		$className = basename($classFile, '.class.php');
		if (!class_exists($className, false)) {
			include $classFile;
		}
		if (method_exists($className, 'cache')) {
			$obj = new $className();
			$obj -> cache();
		}
	}
}
