Commits

Aziz Light  committed 85af0b7

Fixed many bugs, now the scripts will REALLY work normally.

  • Participants
  • Parent commits 006cac5

Comments (0)

Files changed (1)

 	 * Set to FALSE if you want to set up the class manually and don't want to be asked
 	 * questions when you create a new project.
 	 */
-	const verbose_mode = TRUE;
+	const verbose_mode = FALSE;
 	
 	/*
 	|--NON-verbose mode configuration constants-------------------------------
 		$max = count($args);
 		for ($i = 1; $i < $max; $i++)
 		{
+			// FIXME - The query fire controller new index throws an exception. Instead, it should trigger an error saying that new is a reserved word.
 			if (in_array($args[$i - 1], self::$_valid_cli_params) && in_array($args[$i], self::$_valid_cli_params))
 				throw new Exception('Duplicate keywords detected!');
 		}
 			$name = $this->_get_name($destination);
 		$destination .= $name;
 		
+		/*
+		 * TODO - Create the blocks that will let the user remove the user_guide and license.txt.
+		 * TODO - Create the blocks that will let the user remove welcome controller + view. Fire also need to send a notice advising to change the default route.
+		 */
+		
 		if ($this->_import_ci($destination))
 		{
 			// -Verbose-mode-----------------------------------------------------------
 			if (self::verbose_mode)
 			{
 				// -Move-the-application folder--------------------------------------------
-				$_default_answer = (self::move_application_folder) ? 'yes' : 'no';
-				$_question  = 'Do you want to move the application folder outside of the system folder? [Default: ' . $_default_answer . ']';
-				echo $_question;
-				
-				$_answer = strtolower(trim(fgets(STDIN)));
-				
-				if ($_answer == 'yes' || $_answer == 'y' || (empty($_answer) && $_default_answer == 'yes'))
+				// NOTE - If the application folder is not in the system folder, that would mean one of two things:
+				//        - The application_folder_name constant is not the same as the application folder's name.
+				//        - You have manually moved the application folder.
+				//      - In both cases, the user won't be asked wether or not he wants to move the application
+				//        folder out of the system folder.
+				if (is_dir($destination . 'system/' . self::application_folder_name))
 				{
-					if (!$this->_move_application_folder($destination))
+					$_default_answer = (self::move_application_folder) ? 'yes' : 'no';
+					$_question  = 'Do you want to move the application folder outside of the system folder? [Default: ' . $_default_answer . ']';
+					echo $_question;
+					
+					$_answer = strtolower(trim(fgets(STDIN)));
+					
+					if ($_answer == 'yes' || $_answer == 'y' || (empty($_answer) && $_default_answer == 'yes'))
 					{
-						$_error = 'Unable to move the application folder...';
-						self::_display_message('error', $_error, TRUE);
-						unset($_error);
+						if (!$this->_move_application_folder($destination))
+						{
+							$_error = 'Unable to move the application folder...';
+							self::_display_message('error', $_error, TRUE);
+							unset($_error);
+						}
 					}
-				}
-				elseif ($_answer != 'no' || $_answer != 'n')
-				{
-					$i = 0;
-					do
+					elseif ($_answer != 'no' || $_answer != 'n')
 					{
-						echo 'I do not understand...' . "\n";
-						echo $_question;
-						$_answer = strtolower(trim(fgets(STDIN)));
-						if ($_answer == 'yes' || $_answer == 'y' || (empty($_answer) && $_default_answer == 'yes'))
+						$i = 0;
+						do
 						{
-							if (!$this->_move_application_folder($destination))
+							echo 'I do not understand...' . "\n";
+							echo $_question;
+							$_answer = strtolower(trim(fgets(STDIN)));
+							if ($_answer == 'yes' || $_answer == 'y' || (empty($_answer) && $_default_answer == 'yes'))
 							{
-								$_error = 'Unable to move the application folder...';
-								self::_display_message('error', $_error, TRUE);
-								unset($_error);
+								if (!$this->_move_application_folder($destination))
+								{
+									$_error = 'Unable to move the application folder...';
+									self::_display_message('error', $_error, TRUE);
+									unset($_error);
+								}
+								$i = 42;
 							}
-							$i = 42;
-						}
-						elseif ($_answer == 'no' || $_answer == 'n')
+							elseif ($_answer == 'no' || $_answer == 'n')
+							{
+								$i = 42;
+							}
+							$i++;
+						} while ($i < 3);
+					
+						if ($i < 42)
 						{
-							$i = 42;
-						}
-						$i++;
-					} while ($i < 3);
-					
-					if ($i < 42)
-					{
-						$_warning = 'No understandable answer was provided to the previous question...The choice will be made for you...';
-						self::_display_message('warning', $_warning);
-						unset($_warning);
+							$_warning = 'No understandable answer was provided to the previous question...The choice will be made for you...';
+							self::_display_message('warning', $_warning);
+							unset($_warning);
 						
-						if (self::move_application_folder == 'yes')
-						{
-							if (!$this->_move_application_folder($destination))
+							if (self::move_application_folder == 'yes')
 							{
-								$_error = 'Unable to move the application folder...';
-								self::_display_message('error', $_error, TRUE);
-								unset($_error);
+								if (!$this->_move_application_folder($destination))
+								{
+									$_error = 'Unable to move the application folder...';
+									self::_display_message('error', $_error, TRUE);
+									unset($_error);
+								}
 							}
 						}
 					}
 				// ------------------------------------------------------------------------
 				
 				// -Create-assets-folder---------------------------------------------------
-				$_default_answer = (self::create_assets_folder) ? 'yes' : 'no';
-				$_question  = 'Do you want to create an assets folder? [Default: ' . $_default_answer . '] ';
-				echo $_question;
-				
-				$_answer = strtolower(trim(fgets(STDIN)));
-				if ($_answer == 'yes' || $_answer = 'y' || (empty($_answer) && $_default_answer == 'yes'))
+				// NOTE - The assets folder will only be created if it's not already there.
+				if (!is_dir($destination . self::name_of_assets_folder))
 				{
-					if (!$this->_create_assets_folders($destination))
+					$_default_answer = (self::create_assets_folder) ? 'yes' : 'no';
+					$_question  = 'Do you want to create an assets folder? [Default: ' . $_default_answer . '] ';
+					echo $_question;
+					
+					$_answer = strtolower(trim(fgets(STDIN)));
+					if ($_answer == 'yes' || $_answer = 'y' || (empty($_answer) && $_default_answer == 'yes'))
 					{
-						$_error = 'Unable to create the assets folder...';
-						self::_display_message('error', $_error, TRUE);
-						unset($_error);
+						if (!$this->_create_assets_folders($destination))
+						{
+							$_error = 'Unable to create the assets folder...';
+							self::_display_message('error', $_error, TRUE);
+							unset($_error);
+						}
 					}
-				}
-				elseif ($_answer != 'no' || $_answer != 'n')
-				{
-					$i = 0;
-					do
+					elseif ($_answer != 'no' || $_answer != 'n')
 					{
-						echo 'I do not understand...' . "\n";
-						echo $_question;
-						$_answer = strtolower(trim(fgets(STDIN)));
-						if ($_answer == 'yes' || $_answer == 'y' || (empty($_answer) && $_default_answer == 'yes'))
+						$i = 0;
+						do
 						{
-							if (!$this->_create_assets_folders($destination))
+							echo 'I do not understand...' . "\n";
+							echo $_question;
+							$_answer = strtolower(trim(fgets(STDIN)));
+							if ($_answer == 'yes' || $_answer == 'y' || (empty($_answer) && $_default_answer == 'yes'))
 							{
-								$_error = 'Unable to create the assets folder...';
-								self::_display_message('error', $_error, TRUE);
-								unset($_error);
+								if (!$this->_create_assets_folders($destination))
+								{
+									$_error = 'Unable to create the assets folder...';
+									self::_display_message('error', $_error, TRUE);
+									unset($_error);
+								}
+								$i = 42;
 							}
-							$i = 42;
-						}
-						elseif ($_answer == 'no' || $_answer == 'n')
+							elseif ($_answer == 'no' || $_answer == 'n')
+							{
+								$i = 42;
+							}
+							$i++;
+						} while ($i < 3);
+						
+						if ($i < 42)
 						{
-							$i = 42;
-						}
-						$i++;
-					} while ($i < 3);
-					
-					if ($i < 42)
-					{
-						$_warning = 'No understandable answer was provided to the previous question...The choice will be made for you...';
-						self::_display_message('warning', $_warning);
-						unset($_warning);
-						
-						if (self::create_assets_folder == 'yes')
-						{
-							if (!$this->_create_assets_folders($destination))
+							$_warning = 'No understandable answer was provided to the previous question...The choice will be made for you...';
+							self::_display_message('warning', $_warning);
+							unset($_warning);
+							
+							if (self::create_assets_folder == 'yes')
 							{
-								$_error = 'Unable to create the assets folder...';
-								self::_display_message('error', $_error, TRUE);
-								unset($_error);
+								if (!$this->_create_assets_folders($destination))
+								{
+									$_error = 'Unable to create the assets folder...';
+									self::_display_message('error', $_error, TRUE);
+									unset($_error);
+								}
 							}
 						}
 					}
+					
+					unset($_answer, $_question, $_default_answer);
 				}
-				
-				unset($_answer, $_question, $_default_answer);
 				// ------------------------------------------------------------------------
 			} // End of Verbose mode
 			else
 				// -Non-Verbose-Mode-------------------------------------------------------
 				if (self::move_application_folder == 'yes')
 				{
-					if (!$this->_move_application_folder($destination))
+					if (is_dir($destination . '/system/' . self::application_folder_name))
 					{
-						$_error = 'Unable to move the application folder...';
-						self::_display_message('error', $_error, TRUE);
-						unset($_error);
+						if (!$this->_move_application_folder($destination))
+						{
+							$_error = 'Unable to move the application folder...';
+							self::_display_message('error', $_error, TRUE);
+							unset($_error);
+						}
 					}
 				}
 				
 				if (self::create_assets_folder == 'yes')
 				{
-					if (!$this->_create_assets_folders($destination))
+					if (!is_dir($destination . '/' . self::name_of_assets_folder))
 					{
-						$_error = 'Unable to create the assets folder...';
-						self::_display_message('error', $_error, TRUE);
-						unset($_error);
+						if (!$this->_create_assets_folders($destination))
+						{
+							$_error = 'Unable to create the assets folder...';
+							self::_display_message('error', $_error, TRUE);
+							unset($_error);
+						}
 					}
 				}
 			}
 	{
 		if (substr($project_path, - 1) != '/')
 			$project_path .= '/';
-		// @
-		return (rename($project_path . 'system/' . self::application_folder_name, $project_path . self::application_folder_name));
+			
+		if (!is_dir($project_path . 'system/' . self::application_folder_name))
+		{
+			$_notice  = "The application folder wasn't found in the system folder.\n";
+			$_notice .= "- Check that the application_folder_name constant is the same as the application folder's name.\n";
+			$_notice .= "- If it's the same, that would probably mean that you manually moved the application folder. In that case, you should set the move_application_folder constant to FALSE.";
+			self::_display_message($_notice);
+			unset($_notice);
+			
+			return TRUE;
+		}
+		
+		return (@rename($project_path . 'system/' . self::application_folder_name, $project_path . self::application_folder_name));
 	} // End of _move_application_folder
 	
 // ------------------------------------------------------------------------
 		if (substr($project_path, - 1) != '/')
 			$project_path .= '/';
 		
-		// @
-		if (!mkdir($project_path . self::name_of_assets_folder, 0755))
+		if (!@mkdir($project_path . self::name_of_assets_folder, 0755))
 		{
 			return FALSE;
 		}
 		
 		foreach ($this->_assets_subfolders as $asset)
 		{
-			// @
-			if (!mkdir($project_path . self::name_of_assets_folder . '/' . $asset, 0755))
+			if (!@mkdir($project_path . self::name_of_assets_folder . '/' . $asset, 0755))
 			{
 				// if (!$this->_remove_assets_folder($project_path))
 				if (!$this->_recursive_remove_directory($project_path))
 // ------------------------------------------------------------------------
 	
 	/**
-	 * Remove the assets folder and all of its subfolders.
-	 *
-	 * @access private
-	 * @param string $directory : The directory where the new project was created.
-	 * @return bool
-	 * @author Aziz Light
-	 */
-	private function _remove_assets_folder($directory)
-	{
-		if (substr($directory, -1) == '/')
-		{
-			$directory = substr($directory, 0, -1);
-		}
-		
-		if (!file_exists($directory) || !is_dir($directory))
-		{
-			return FALSE;
-		}
-		else
-		{
-			$handle = opendir($directory);
-			while (FALSE !== ($item = readdir($handle)))
-			{
-				if ($item != '.' && $item != '..')
-				{
-					$path = $directory . '/' . $item;
-					if (!rmdir($path))
-					{
-						return FALSE;
-					}
-				}
-			}
-			closedir($handle);
-			
-			return TRUE;
-		}
-	} // End of _remove_assets_folder
-	
-// ------------------------------------------------------------------------
-	
-	/**
 	 * Remove a folder and all of its contents.
 	 *
 	 * @access private
-	 * @param string $directory : the path to the folder to remove.
+	 * @param string $directory : The path to the folder to remove.
 	 * @param bool $empty : If TRUE, the directory and subdirectories will be emptied but not removed.
 	 * @return bool
 	 * @author lixlpixel
 			$controller .= "\t{\n";
 				$controller .= "\t\tparent::" . self::parent_controller_constructor . "();\n";
 			$controller .= "\t}\n";
-		
-			$controller .= "\t\n";
-			$controller .= "\t// ------------------------------------------------------------------------\n";
-			$controller .= "\t\n";
-			
-		
-			$controller .= "\tpublic function index()\n";
-			$controller .= "\t{\n";
-				$controller .= "\t\t\n";
-			$controller .= "\t} // End of index\n";
 			$controller .= "\t\n";
 			
 			$controller  = $this->_add_actions($controller);
 	 */
 	public function create()
 	{
+		// FIXME - Controller and model generation broken
 		if (empty($this->name))
 		{
 			$this->name = $this->_get_name();
 		
 		$this->_actions[] = $_action;
 		
-		print_r($this->_action);
-		
 		return TRUE;
 	} // End of new_action
 	
 	 * Add a parameter to a controller's action or a model's medthod
 	 *
 	 * @access public
-	 * @param string $name : the name of the parameter (the name of the variable)
+	 * @param string $name : The name of the parameter (the name of the variable)
 	 * @return bool
 	 * @author Aziz Light
 	 */
 	 */
 	private function _make($config)
 	{
+		echo "\n\nmake called\n\n";
+		
 		$file = './' . $config['type'] . 's/' . $config['filename'] . '.php';
 		
 		if (file_exists($file))
 			$i = 0;
 			do {
 				echo "Do you want to overwrite ${file}? [Default: y]\n[y/n] ";
-				$_answer = fgets(STDIN);
-				if (trim($_answer) == 'n')
+				$_answer = trim(fgets(STDIN));
+				if ($_answer == 'n')
 				{
 					exit();
 				}
-				elseif (trim($_answer) == 'y')
+				elseif ($_answer == 'y' || empty($_answer))
 				{
 					$i = 42;
 				}
 				else
 				{
-					echo "I don\'t understand...\n";
+					echo "I don't understand...\n";
 					$i++;
 				}
 				
 			} while ($i < 3);
 			unset($_answer);
 		}
+		else
+		{
+			$i = 42;
+		}
 		
 		if ($i > 3)
 		{
 				default:
 					if ($last_type == 'new')
 					{
+						if ($argv[$i - 1] == 'new')
+							break;
 						$fire->new_action($argv[$i]);
 					}
 					else