<commit_before><?php
/**
 *  \details &copy; 2011  Open Ximdex Evolution SL [http://www.ximdex.org]
 *
 *  Ximdex a Semantic Content Management System (CMS)
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published
 *  by the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  See the Affero GNU General Public License for more details.
 *  You should have received a copy of the Affero GNU General Public License
 *  version 3 along with Ximdex (see LICENSE file).
 *
 *  If not, visit http://gnu.org/licenses/agpl-3.0.html.
 *
 *  @author <NAME> <<EMAIL>>
 *  @version $Revision$
 */




if (!defined('XIMDEX_ROOT_PATH')) {
	define ('XIMDEX_ROOT_PATH', realpath(dirname(__FILE__). "/../../"));
}
require_once(XIMDEX_ROOT_PATH . '/inc/patterns/Factory.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/parsers/ParsingJsGetText.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/model/action.inc');
require_once(XIMDEX_ROOT_PATH . '/inc/mvc/IController.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/serializer/Serializer.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/modules/ModulesManager.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/model/ActionsStats.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/notifications/AbstractNotificationStrategy.class.php');


/**
 *
 * @brief Base abstract class for Actions
 *
 *  Base abstract class for Actions who provides basic funcionality like rendering
 *  css/js inclusion and redirection
 *
 */

class ActionAbstract extends IController {

	/**
	 * Keeps the js to use
	 * @var unknown_type
	 */
	private $_js = array();

	/**
	 * keeps the css to use
	 * @var unknown_type
	 */
	private $_css = array();

	/**
	 * Action name
	 */
	private $actionName = '';

	/**
	 * Action description
	 */
	private $actionDescription = '';

	/**
	 * Action renderer
	 * @var unknown_type
	 */
	public $renderer;

	/**
	 * Action command
	 * @var String
	 */
	public $actionCommand;

	protected $endActionLogged=false;

	/**
	 * Construct
	 * @param $_render
	 * @return unknown_type
	 */
	function __construct($_render = null) {

		parent::__construct();

		$this->displayEncoding = Config::getValue('displayEncoding');

		/** Obtaining the render to use */
		$rendererClass = $this->_get_render($_render);

		$factory = new Factory(RENDERER_ROOT_PATH, '');
		$this->renderer = $factory->instantiate($rendererClass.'Renderer');

		$this->renderer->set("_BASE_TEMPLATE_PATH", sprintf('%s/xmd/template/%s/', XIMDEX_ROOT_PATH, $rendererClass)  );

	}

	private function getActionInfo($actionName, $module, $actionId, $nodeId) {

		$node = new Node();
		$nodeTypeId = $node->find('IdNodeType', 'IdNode = %s', array($nodeId), MONO);
		$nodeTypeId = $nodeTypeId[0];
		
		$action = new Action();
		$data = $action->find(
			'Command, Name, Description',
			'IdNodeType = %s and Command = %s and Module is %s',
			array($nodeTypeId, $actionName, $module)
		);

		$data = $data[0];
		
		//debug::log($data,$actionName, $module, $actionId, $nodeId);
		return $data;
	}

	/**
	 * Execute the action
	 * @param $request
	 * @return unknown_type
	 */
	function execute($request) {
		// Setting path or subset which current action belongs to
		$nodeid = $request->getParam("nodeid");
		$action = $request->getParam("action");
		$actionid = $request->getParam("actionid");

		if ($nodeid && $actionid) {
			$action = new Action($actionid);
			//XMD_Log::debug("MVC::ActionAbstract calling action $actionid (" . $action->get('Command') . ") in node $nodeid ");
		}

		$method = ($var = $request->getParam("method")) ? $var : 'index';
		$this->request = $request;

		$actionInfo = $this->getActionInfo(
			$request->getParam('action'),
			$request->getParam('module'),
			$request->getParam('actionid'),
			$request->getParam('nodeid')
		);

		$this->actionCommand = $actionInfo['Command'];
		$this->actionName = $actionInfo['Name'];		
		$this->actionDescription = $actionInfo['Description'];
		$this->actionModule = $actionInfo['Module'];
		$command = $this->actionCommand = $actionInfo['Command'];		

		if(method_exists($this, $method)) {
			$this->actionMethod = $method;
			$this->logInitAction();
			$this->$method();
		} else {
			XMD_Log::debug("MVC::ActionAbstract Metodo {$method} not found" );
		}

	}

	private function getDefaultLogMessage(){
		$user = XSession::get("userID")? "by ".XSession::get("userID"):"";
		$moduleString = $this->actionModule? "in module {$this->actionModule}.": "";
		return $moduleString.get_class($this)."->{$this->actionMethod} {$user}";

	}

	private function logInitAction(){

		$this->endActionLogged = false;
		Action_log::info("Init ".$this->getDefaultLogMessage());
		Action_log::debug("Request: ".print_r($this->request, true));

	}

	protected function logEndAction($success=true, $message=null){

		$message = $message? ". $message": "";
		if ($success)
			Action_log::info("OK ".$this->getDefaultLogMessage()." $message");
		else
			Action_log::error("FAIL ".$this->getDefaultLogMessage()." $message");

		$this->endActionLogged=true;
	}
	
	protected function logSuccessAction($message = null){
		$this->logEndAction(true, $message);
	}
<commit_msg>Changing message in default end Action<commit_after><?php
/**
 *  \details &copy; 2011  Open Ximdex Evolution SL [http://www.ximdex.org]
 *
 *  Ximdex a Semantic Content Management System (CMS)
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published
 *  by the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  See the Affero GNU General Public License for more details.
 *  You should have received a copy of the Affero GNU General Public License
 *  version 3 along with Ximdex (see LICENSE file).
 *
 *  If not, visit http://gnu.org/licenses/agpl-3.0.html.
 *
 *  @author Ximdex DevTeam <<EMAIL>>
 *  @version $Revision$
 */




if (!defined('XIMDEX_ROOT_PATH')) {
	define ('XIMDEX_ROOT_PATH', realpath(dirname(__FILE__). "/../../"));
}
require_once(XIMDEX_ROOT_PATH . '/inc/patterns/Factory.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/parsers/ParsingJsGetText.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/model/action.inc');
require_once(XIMDEX_ROOT_PATH . '/inc/mvc/IController.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/serializer/Serializer.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/modules/ModulesManager.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/model/ActionsStats.class.php');
require_once(XIMDEX_ROOT_PATH . '/inc/notifications/AbstractNotificationStrategy.class.php');


/**
 *
 * @brief Base abstract class for Actions
 *
 *  Base abstract class for Actions who provides basic funcionality like rendering
 *  css/js inclusion and redirection
 *
 */

class ActionAbstract extends IController {

	/**
	 * Keeps the js to use
	 * @var unknown_type
	 */
	private $_js = array();

	/**
	 * keeps the css to use
	 * @var unknown_type
	 */
	private $_css = array();

	/**
	 * Action name
	 */
	private $actionName = '';

	/**
	 * Action description
	 */
	private $actionDescription = '';

	/**
	 * Action renderer
	 * @var unknown_type
	 */
	public $renderer;

	/**
	 * Action command
	 * @var String
	 */
	public $actionCommand;

	protected $endActionLogged=false;

	/**
	 * Construct
	 * @param $_render
	 * @return unknown_type
	 */
	function __construct($_render = null) {

		parent::__construct();

		$this->displayEncoding = Config::getValue('displayEncoding');

		/** Obtaining the render to use */
		$rendererClass = $this->_get_render($_render);

		$factory = new Factory(RENDERER_ROOT_PATH, '');
		$this->renderer = $factory->instantiate($rendererClass.'Renderer');

		$this->renderer->set("_BASE_TEMPLATE_PATH", sprintf('%s/xmd/template/%s/', XIMDEX_ROOT_PATH, $rendererClass)  );

	}

	private function getActionInfo($actionName, $module, $actionId, $nodeId) {

		$node = new Node();
		$nodeTypeId = $node->find('IdNodeType', 'IdNode = %s', array($nodeId), MONO);
		$nodeTypeId = $nodeTypeId[0];
		
		$action = new Action();
		$data = $action->find(
			'Command, Name, Description',
			'IdNodeType = %s and Command = %s and Module is %s',
			array($nodeTypeId, $actionName, $module)
		);

		$data = $data[0];
		
		//debug::log($data,$actionName, $module, $actionId, $nodeId);
		return $data;
	}

	/**
	 * Execute the action
	 * @param $request
	 * @return unknown_type
	 */
	function execute($request) {
		// Setting path or subset which current action belongs to
		$nodeid = $request->getParam("nodeid");
		$action = $request->getParam("action");
		$actionid = $request->getParam("actionid");

		if ($nodeid && $actionid) {
			$action = new Action($actionid);
			//XMD_Log::debug("MVC::ActionAbstract calling action $actionid (" . $action->get('Command') . ") in node $nodeid ");
		}

		$method = ($var = $request->getParam("method")) ? $var : 'index';
		$this->request = $request;

		$actionInfo = $this->getActionInfo(
			$request->getParam('action'),
			$request->getParam('module'),
			$request->getParam('actionid'),
			$request->getParam('nodeid')
		);

		$this->actionCommand = $actionInfo['Command'];
		$this->actionName = $actionInfo['Name'];		
		$this->actionDescription = $actionInfo['Description'];
		$this->actionModule = $actionInfo['Module'];
		$command = $this->actionCommand = $actionInfo['Command'];		

		if(method_exists($this, $method)) {
			$this->actionMethod = $method;
			$this->logInitAction();
			$this->$method();
		} else {
			XMD_Log::debug("MVC::ActionAbstract Metodo {$method} not found" );
		}

	}

	private function getDefaultLogMessage(){
		$user = XSession::get("userID")? "by ".XSession::get("userID"):"";
		$moduleString = $this->actionModule? "in module {$this->actionModule}.": "";
		return $moduleString.get_class($this)."->{$this->actionMethod} {$user}";

	}

	private function logInitAction(){

		$this->endActionLogged = false;
		Action_log::info("Init ".$this->getDefaultLogMessage());
		Action_log::debug("Request: ".print_r($this->request, true));

	}

	protected function logEndAction($success=true, $message=null){

		$message = $message? ". $message": "";
		if ($success)
			Action_log::info("FINISH OK ".$this->getDefaultLogMessage()." $message");
		else
			Action_log::error("FINISH FAIL ".$this->getDefaultLogMessage()." $message");

		$this->endActionLogged=true;
	}
	
	protected function logSuccessAction($message = null){
		$this->logEndAction(true, $message);
	}

{'fraction_non_alphanumeric': 0.16069665140497352, 'fraction_numerical': 0.0017954933117874136, 'mean_word_length': 4.307289185326346, 'pattern_counts': {'":': 4, '<': 10, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1663909', 'n_tokens_mistral': 3798, 'n_tokens_neox': 3508, 'n_words': 846}