<commit_before><?php
/**
 * Generate and alter tables to reflect base models and association models
 * @author <NAME> | grrr.nl
 * @package Garp
 * @subpackage Model
 */
class Garp_Model_Spawn_MySql_Manager {
	/** @param Array $_models Array of Garp_Model_Spawn_Model objects */
	protected $_modelSet;
	protected $_adapter;
	
	const CUSTOM_SQL_PATH = '/data/sql/spawn.sql';


	/**
	 * @param Garp_Model_Spawn_ModelSet 	$modelSet 		The model set to model the database after.
	 * @param Array 						&$changelist 	An array of strings, describing the changes made to the database in this Spawn session.
	 */
	public function __construct(Garp_Model_Spawn_ModelSet $modelSet) {
		$totalActions = count($modelSet) * 4;
		$progress = Garp_Cli_Ui_ProgressBar::getInstance();
		$progress->init($totalActions);
		$progress->display("Initializing database...");

		$priorityModel = 'User';

		$this->_modelSet = $modelSet;
		$this->_adapter = Zend_Db_Table::getDefaultAdapter();
		$this->_adapter->query('SET NAMES utf8;');


		//	Stage 1: Spawn the prioritized table first
		if (array_key_exists($priorityModel, $modelSet)) {
			$this->_createBaseModelTableAndAdvance($modelSet[$priorityModel]);
		}

		//	Stage 2: Create the rest of the base models' tables
		foreach ($modelSet as $model) {
			if ($model->id !== $priorityModel) {
				$this->_createBaseModelTableAndAdvance($model);
			}
		}

		//	Stage 3: Create base model views
		foreach ($modelSet as $model) {
			$progress->display($model->id . " joint view");
			/* $this->_createJointView($model); */
			$progress->advance();
		}

		//	Stage 4: Create binding models
		foreach ($modelSet as $model) {
			$progress->display($model->id . " many-to-many config reading");
			$habtmRelations = $model->relations->getRelations('type', 'hasAndBelongsToMany');
			if ($habtmRelations) {
				foreach ($habtmRelations as $relation) {
					if (strcmp($model->id, $relation->model) <= 0) {
						//	only sync binding tables from models A -> B, not from B -> A
						$this->_createBindingModelTableIfNotExists($relation);
					}
				}
			}
			$progress->advance();
		}

		//	Stage 5: Sync base and binding models
		foreach ($modelSet as $model) {
			$this->_syncBaseModel($model);

			$habtmRelations = $model->relations->getRelations('type', 'hasAndBelongsToMany');
			if ($habtmRelations) {
				foreach ($habtmRelations as $relation) {
					if (strcmp($model->id, $relation->model) <= 0) {
						//	only sync binding tables from models A -> B, not from B -> A
						$this->_syncBindingModel($relation);
					}
				}<commit_msg>Temp fix<commit_after><?php
/**
 * Generate and alter tables to reflect base models and association models
 * @author <NAME> | grrr.nl
 * @package Garp
 * @subpackage Model
 */
class Garp_Model_Spawn_MySql_Manager {
	/** @param Array $_models Array of Garp_Model_Spawn_Model objects */
	protected $_modelSet;
	protected $_adapter;
	
	const CUSTOM_SQL_PATH = '/data/sql/spawn.sql';


	/**
	 * @param Garp_Model_Spawn_ModelSet 	$modelSet 		The model set to model the database after.
	 * @param Array 						&$changelist 	An array of strings, describing the changes made to the database in this Spawn session.
	 */
	public function __construct(Garp_Model_Spawn_ModelSet $modelSet) {
		$totalActions = count($modelSet) * 4;
		$progress = Garp_Cli_Ui_ProgressBar::getInstance();
		$progress->init($totalActions);
		$progress->display("Initializing database...");

		$priorityModel = 'User';

		$this->_modelSet = $modelSet;
		$this->_adapter = Zend_Db_Table::getDefaultAdapter();
		$this->_adapter->query('SET NAMES utf8;');


		//	Stage 1: Spawn the prioritized table first
		if (array_key_exists($priorityModel, $modelSet)) {
			$this->_createBaseModelTableAndAdvance($modelSet[$priorityModel]);
		}

		//	Stage 2: Create the rest of the base models' tables
		foreach ($modelSet as $model) {
			if ($model->id !== $priorityModel) {
				$this->_createBaseModelTableAndAdvance($model);
			}
		}

		//	Stage 3: Create base model views
		foreach ($modelSet as $model) {
			$progress->display($model->id . " joint view");
			$this->_createJointView($model);
			$progress->advance();
		}

		//	Stage 4: Create binding models
		foreach ($modelSet as $model) {
			$progress->display($model->id . " many-to-many config reading");
			$habtmRelations = $model->relations->getRelations('type', 'hasAndBelongsToMany');
			if ($habtmRelations) {
				foreach ($habtmRelations as $relation) {
					if (strcmp($model->id, $relation->model) <= 0) {
						//	only sync binding tables from models A -> B, not from B -> A
						$this->_createBindingModelTableIfNotExists($relation);
					}
				}
			}
			$progress->advance();
		}

		//	Stage 5: Sync base and binding models
		foreach ($modelSet as $model) {
			$this->_syncBaseModel($model);

			$habtmRelations = $model->relations->getRelations('type', 'hasAndBelongsToMany');
			if ($habtmRelations) {
				foreach ($habtmRelations as $relation) {
					if (strcmp($model->id, $relation->model) <= 0) {
						//	only sync binding tables from models A -> B, not from B -> A
						$this->_syncBindingModel($relation);
					}
				}
{'fraction_non_alphanumeric': 0.1414891538010553, 'fraction_numerical': 0.0035176861442251317, 'mean_word_length': 3.846590909090909, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '240779', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1590, 'n_words': 415}