예제 #1
0
		/**
		 * The CdiQueryLog::log() function is called from the Database implementation responsible for executing Symphony SQL queries
		 * If in MASTER mode, CDI will save the query to disk allowing it to be committed to the VCS. From there it will be available
		 * for automatic query exection by CDI slave instances (see also CdiLogQuery::executeQueries()).
		 * @param String $query
		 */
		public static function log($query) {
			// Prevent execution on the frontend and check configuration conditions
			// Do not log the query when CDI is disabled, in SLAVE mode or busy executing queries.
			// Additionally if the logger is not installed, you should not be able to call this function
			if((!class_exists('Administration')) || !CdiUtil::isEnabled() || self::$isUpdating) {
				return true;
			}
			
			$query = trim($query);
			$tbl_prefix = Symphony::Configuration()->get('tbl_prefix', 'database');
	
			/* FILTERS */
			// do not register changes to tbl_cdi_log
			if (preg_match("/{$tbl_prefix}cdi_log/i", $query)) return true;
			// only structural changes, no SELECT statements
			if (!preg_match('/^(insert|update|delete|create|drop|alter|rename)/i', $query)) return true;
			// un-tracked tables (sessions, cache, authors)
			if (preg_match("/{$tbl_prefix}(authors|cache|forgotpass|sessions)/i", $query)) return true;
			// content updates in tbl_entries (includes tbl_entries_fields_*)
			if (preg_match('/^(insert|delete|update)/i', $query) && preg_match("/({$config->tbl_prefix}entries)/i", $query)) return true;
			// append query delimeter if it doesn't exist
			if (!preg_match('/;$/', $query)) $query .= ";";

			// Replace the table prefix in the query
			// This allows query execution on slave instances with different table prefix.
			$query = str_replace($tbl_prefix,'tbl_',$query);
			
			// We've come far enough... let's try to save it to disk!
			if(CdiUtil::isCdiMaster()) {
				return CdiMaster::persistQuery($query);
			} else if(CdiUtil::isCdiDBSyncMaster()) {
				return CdiDBSync::persistQuery($query);
			} else {
				//TODO: error handling for the unusual event that we are dealing with here.
				return true;
			}
		}
예제 #2
0
		public static function appendDBSyncPreferences() {
			$header = new XMLElement('div',null, array('class' => 'cdiHeader'));
			$main = new XMLElement('div',null,array('class' => 'group'));
			$leftColumn = new XMLElement('div',null);
			$rightColumn = new XMLElement('div',null);
			$footer = new XMLElement('div',null, array('class' => 'cdiFooter'));
						
				if(CdiUtil::isCdiDBSyncMaster()) {
					if(file_exists(CDI_DB_SYNC_FILE) && CdiUtil::hasDumpDBInstalled()) {
						$header->appendChild(self::appendInstanceMode());
						$leftColumn->appendChild(self::appendDownloadLog());
						$leftColumn->appendChild(self::appendClearLog());
						$rightColumn->appendChild(self::appendDBExport());
						$rightColumn->appendChild(self::appendRestore());
					} else if(file_exists(CDI_DB_SYNC_FILE) && !CdiUtil::hasDumpDBInstalled()) {
						$header->appendChild(self::appendInstanceMode());
						$leftColumn->appendChild(self::appendClearLog());
						$rightColumn->appendChild(self::appendDumpDB());
					} else if(!file_exists(CDI_DB_SYNC_FILE) && CdiUtil::hasDumpDBInstalled()) {
						$leftColumn->appendChild(self::appendInstanceMode());
						$rightColumn->appendChild(self::appendDBExport());
						$footer->appendChild(self::appendRestore());
					} else if(!file_exists(CDI_DB_SYNC_FILE) && !CdiUtil::hasDumpDBInstalled()) {
						$leftColumn->appendChild(self::appendInstanceMode());
						$rightColumn->appendChild(self::appendDumpDB());
					}
				} else if(CdiUtil::isCdiDBSyncSlave()) {
					if(file_exists(CDI_DB_SYNC_FILE) && CdiUtil::hasDumpDBInstalled()) {
						$leftColumn->appendChild(self::appendInstanceMode());
						$leftColumn->appendChild(self::appendDBSyncImport());
						$leftColumn->appendChild(self::appendDBSyncImportFile());
						$leftColumn->appendChild(self::appendClearLog());
						$rightColumn->appendChild(self::appendDumpDB());
						$rightColumn->appendChild(self::appendDBExport());
						$rightColumn->appendChild(self::appendRestore());
					} else if(file_exists(CDI_DB_SYNC_FILE) && !CdiUtil::hasDumpDBInstalled()) {
						$header->appendChild(self::appendInstanceMode());
						$leftColumn->appendChild(self::appendDBSyncImport());
						$leftColumn->appendChild(self::appendDBSyncImportFile());
						$leftColumn->appendChild(self::appendClearLog());
						$rightColumn->appendChild(self::appendDumpDB());
					} else if(!file_exists(CDI_DB_SYNC_FILE) && CdiUtil::hasDumpDBInstalled()) {
						$leftColumn->appendChild(self::appendInstanceMode());
						$leftColumn->appendChild(self::appendDBSyncImport());
						$leftColumn->appendChild(self::appendDBSyncImportFile());
						$rightColumn->appendChild(self::appendDumpDB());
						$rightColumn->appendChild(self::appendDBExport());
						$footer->appendChild(self::appendRestore());
					} else if(!file_exists(CDI_DB_SYNC_FILE) && !CdiUtil::hasDumpDBInstalled()) {
						$header->appendChild(self::appendInstanceMode());
						$leftColumn->appendChild(self::appendDBSyncImport());
						$leftColumn->appendChild(self::appendDBSyncImportFile());
						$rightColumn->appendChild(self::appendDumpDB());
					}
				}

			// Add sections to preference group
			$cdiMode =  (CdiUtil::isCdiMaster() ? "CdiMaster" : 
						(CdiUtil::isCdiSlave() ? "CdiSlave" :
						(CdiUtil::isCdiDBSyncMaster() ? "DBSyncMaster" :
						(CdiUtil::isCdiDBSyncSlave() ? "DBSyncSlave" : "unknown"))));
			$section = new XMLElement('div',null,array('class' => 'db_sync ' . $cdiMode));
				
			$section->appendChild($header);
			$main->appendChild($leftColumn);
			$main->appendChild($rightColumn);
			$section->appendChild($main);			
			$section->appendChild($footer);
			return $section;
		}