<commit_before><?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
 * trashAdminController class
 * trash admin the module's controller class
 *
 * @author NAVER (<EMAIL>)
 * @package /modules/trash
 * @version 0.1
 */
class trashAdminController extends trash
{
	/**
	 * object insert to trash
	 * @param TrashVO $obj
	 * @return Object
	 */
	function insertTrash($obj)
	{
		if(!Context::get('is_logged'))
		{
			return new Object(-1, 'msg_not_permitted');
		}

		$logged_info = Context::get('logged_info');

		$oTrashVO = new TrashVO();
		$oTrashVO = &$obj;

		if(!$oTrashVO->getTrashSrl()) $oTrashVO->setTrashSrl(getNextSequence());
		if(!is_string($oTrashVO->getSerializedObject())) $oTrashVO->setSerializedObject(serialize($oTrashVO->getSerializedObject()));
		$oTrashVO->setIpaddress($_SERVER['REMOTE_ADDR']);
		$oTrashVO->setRemoverSrl($logged_info->member_srl);
		$oTrashVO->setRegdate(date('YmdHis'));

		return executeQuery('trash.insertTrash', $oTrashVO);
	}

	/**
	 * Empty trash
	 * @param array trashSrls
	 * @return Object
	 */
	function procTrashAdminEmptyTrash()
	{
		global $lang;
		$isAll = Context::get('is_all');
		$originModule = Context::get('origin_module');
		$tmpTrashSrls = Context::get('cart');
		$is_type = Context::get('is_type');

		$trashSrls = array();
		if($isAll != 'true')
		{
			if(is_array($tmpTrashSrls))
			{
				$trashSrls = $tmpTrashSrls;
			}
			else
			{
				$trashSrls = explode('|@|', $tmpTrashSrls);
			}
		}

		//module relation data delete...
		$output = $this->_relationDataDelete($isAll, $is_type, $trashSrls);
		if(!$output->toBool()) return new Object(-1, $output->message);

		if(!$this->_emptyTrash($trashSrls)) return new Object(-1, $lang->fail_empty);

		$this->setMessage('success_deleted', 'info');

		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispTrashAdminList', 'origin_module', $originModule);
		$this->setRedirectUrl($returnUrl, $output);
	}

	/**
	 * Empty trash - private method
	 * @param string $isAll
	 * @param string $is_type
	 * @param array trashSrls
	 * @return Object
	 */
	function _relationDataDelete($isAll, $is_type, &$trashSrls)
	{
		$oTrashModel = getModel('trash');
		if($isAll == 'true')
		{
			$args = new stdClass();
			$args->originModule = $is_type;
			$output = $oTrashModel->getTrashAllList($args);

			if(!$output->toBool())
			{
				return new Object(-1, $output->message);
			}

			if(is_array($output->data))
			{
				foreach($output->data as $value)
				{
					$trashSrls[] = $value->getTrashSrl();
				}
			}
		}
		else
		{
			$args = new stdClass();
			$args->trashSrl = $trashSrls;
			$output = $oTrashModel->getTrashList($args);
			if(!$output->toBool())
			{
				return new Object(-1, $output->message);
			}
		}

		if(is_array($output->data))
		{
			foreach($output->data as $oTrashVO)
			{
				//class file check
				$classPath = ModuleHandler::getModulePath($oTrashVO->getOriginModule());
				if(!is_dir(FileHandler::getRealPath($classPath))) return new Object(-1, 'not exist restore module directory');

				$classFile = sprintf('%s%s.admin.controller.php', $classPath, $oTrashVO->getOriginModule());
				$classFile = FileHandler::getRealPath($classFile);
				if(!file_exists($classFile)) return new Object(-1, 'not exist restore module class file');

				$oAdminController = getAdminController($oTrashVO->getOriginModule());
				if(!method_exists($oAdminController, 'emptyTrash')) return new Object(-1, 'not exist restore method in module class file');

				$output2 = $oAdminController->emptyTrash($oTrashVO->getSerializedObject());
				if(!$output2->toBool()) return new Object(-1, $output2->message);
			}
		}
		return new Object(0, $lang->success_deleted);
	}

	/**
	 * Restore content object
	 * @return void|Object
	 */
	function procTrashAdminRestore()
	{
		global $lang;
		$trashSrlList = Context::get('cart');

		if(is_array($trashSrlList))
		{
			// begin transaction
			$oDB = &DB::getInstance();
			$oDB->begin();
			// eache restore method call in each classfile
			foreach($trashSrlList as $value)
			{
				$oTrashModel = getModel('trash');
				$output = $oTrashModel->getTrash($value);
				if(!$output->toBool()) return new Object(-1, $output->message);

				//class file check
				$classPath = ModuleHandler::getModulePath($output->data->getOriginModule());
				if(!is_dir(FileHandler::getRealPath($classPath))) return new Object(-1, 'not exist restore module directory');

				$classFile = sprintf('%s%s.admin.controller.php', $classPath, $output->data->getOriginModule());
				$classFile = FileHandler::getRealPath($classFile);
				if(!file_exists($classFile)) return new Object(-1, 'not exist restore module class file');

				$oAdminController = getAdminController($output->data->getOriginModule());
				if(!method_exists($oAdminController, 'restoreTrash')) return new Object(-1, 'not exist restore method in module class file');

				$originObject = unserialize($output->data->getSerializedObject());
				$output = $oAdminController->restoreTrash($originObject);

				if(!$output->toBool())
				{
					$oDB->rollback();
					return new Object(-1, $output->message);
				}
			}

			// restore object delete in trash box
			if(!$this->_emptyTrash($trashSrlList)) {
				$oDB->rollback();
				return new Object(-1, $lang->fail_empty);
			}
			$oDB->commit();
		}

		$this->setMessage('success_restore', 'info');

		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispTrashAdminList');
		$this->setRedirectUrl($returnUrl);
	}

	/**
	 * Set trash list to Context
	 * @return void|Object
	 */
	function procTrashAdminGetList()
	{
		if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted');
		$trashSrls = Context::get('trash_srls');
		if($trashSrls) $trashSrlList = explode(',', $trashSrls);

		if(count($trashSrlList) > 0)
		{
			$oTrashModel = getModel('trash');
			$args = new stdClass();
			$args->trashSrl = $trashSrlList;
			$output = $oTrashModel->getTrashList($args);
			$trashList = $output->data;
		}
		else
		{
			global $lang;
			$trashList = array();
			$this->setMessage($lang->no_documents);
		}

		$oSecurity = new Security($trashList);
		$oSecurity->encodeHTML('..');
		$this->add('trash_list', $trashList);
	}

	/**
	 * empty trash
	 * @param array trashSrls
	 * @return bool
	 */
	function _emptyTrash($trashSrls)
	{
		if(!is_array($trashSrls)) return false;
		$args = new stdClass();
		$args->trashSrls = $trashSrls;
		$output = executeQuery('trash.deleteTrash', $args);
		if(!$output->toBool()) return false;

		return true;
	}
}
/* End of file trash.admin.controller.php */
/* Location: ./modules/trash/trash.admin.controller.php */
<commit_msg>fix language value.<commit_after><?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
 * trashAdminController class
 * trash admin the module's controller class
 *
 * @author NAVER (<EMAIL>)
 * @package /modules/trash
 * @version 0.1
 */
class trashAdminController extends trash
{
	/**
	 * object insert to trash
	 * @param TrashVO $obj
	 * @return Object
	 */
	function insertTrash($obj)
	{
		if(!Context::get('is_logged'))
		{
			return new Object(-1, 'msg_not_permitted');
		}

		$logged_info = Context::get('logged_info');

		$oTrashVO = new TrashVO();
		$oTrashVO = &$obj;

		if(!$oTrashVO->getTrashSrl()) $oTrashVO->setTrashSrl(getNextSequence());
		if(!is_string($oTrashVO->getSerializedObject())) $oTrashVO->setSerializedObject(serialize($oTrashVO->getSerializedObject()));
		$oTrashVO->setIpaddress($_SERVER['REMOTE_ADDR']);
		$oTrashVO->setRemoverSrl($logged_info->member_srl);
		$oTrashVO->setRegdate(date('YmdHis'));

		return executeQuery('trash.insertTrash', $oTrashVO);
	}

	/**
	 * Empty trash
	 * @param array trashSrls
	 * @return Object
	 */
	function procTrashAdminEmptyTrash()
	{
		global $lang;
		$isAll = Context::get('is_all');
		$originModule = Context::get('origin_module');
		$tmpTrashSrls = Context::get('cart');
		$is_type = Context::get('is_type');

		$trashSrls = array();
		if($isAll != 'true')
		{
			if(is_array($tmpTrashSrls))
			{
				$trashSrls = $tmpTrashSrls;
			}
			else
			{
				$trashSrls = explode('|@|', $tmpTrashSrls);
			}
		}

		//module relation data delete...
		$output = $this->_relationDataDelete($isAll, $is_type, $trashSrls);
		if(!$output->toBool()) return new Object(-1, $output->message);

		if(!$this->_emptyTrash($trashSrls)) return new Object(-1, $lang->fail_empty);

		$this->setMessage('success_deleted', 'info');

		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispTrashAdminList', 'origin_module', $originModule);
		$this->setRedirectUrl($returnUrl, $output);
	}

	/**
	 * Empty trash - private method
	 * @param string $isAll
	 * @param string $is_type
	 * @param array trashSrls
	 * @return Object
	 */
	function _relationDataDelete($isAll, $is_type, &$trashSrls)
	{
		$oTrashModel = getModel('trash');
		if($isAll == 'true')
		{
			$args = new stdClass();
			$args->originModule = $is_type;
			$output = $oTrashModel->getTrashAllList($args);

			if(!$output->toBool())
			{
				return new Object(-1, $output->message);
			}

			if(is_array($output->data))
			{
				foreach($output->data as $value)
				{
					$trashSrls[] = $value->getTrashSrl();
				}
			}
		}
		else
		{
			$args = new stdClass();
			$args->trashSrl = $trashSrls;
			$output = $oTrashModel->getTrashList($args);
			if(!$output->toBool())
			{
				return new Object(-1, $output->message);
			}
		}

		if(is_array($output->data))
		{
			foreach($output->data as $oTrashVO)
			{
				//class file check
				$classPath = ModuleHandler::getModulePath($oTrashVO->getOriginModule());
				if(!is_dir(FileHandler::getRealPath($classPath))) return new Object(-1, 'not exist restore module directory');

				$classFile = sprintf('%s%s.admin.controller.php', $classPath, $oTrashVO->getOriginModule());
				$classFile = FileHandler::getRealPath($classFile);
				if(!file_exists($classFile)) return new Object(-1, 'not exist restore module class file');

				$oAdminController = getAdminController($oTrashVO->getOriginModule());
				if(!method_exists($oAdminController, 'emptyTrash')) return new Object(-1, 'not exist restore method in module class file');

				$output2 = $oAdminController->emptyTrash($oTrashVO->getSerializedObject());
				if(!$output2->toBool()) return new Object(-1, $output2->message);
			}
		}
		return new Object(0, lang('success_deleted'));
	}

	/**
	 * Restore content object
	 * @return void|Object
	 */
	function procTrashAdminRestore()
	{
		global $lang;
		$trashSrlList = Context::get('cart');

		if(is_array($trashSrlList))
		{
			// begin transaction
			$oDB = &DB::getInstance();
			$oDB->begin();
			// eache restore method call in each classfile
			foreach($trashSrlList as $value)
			{
				$oTrashModel = getModel('trash');
				$output = $oTrashModel->getTrash($value);
				if(!$output->toBool()) return new Object(-1, $output->message);

				//class file check
				$classPath = ModuleHandler::getModulePath($output->data->getOriginModule());
				if(!is_dir(FileHandler::getRealPath($classPath))) return new Object(-1, 'not exist restore module directory');

				$classFile = sprintf('%s%s.admin.controller.php', $classPath, $output->data->getOriginModule());
				$classFile = FileHandler::getRealPath($classFile);
				if(!file_exists($classFile)) return new Object(-1, 'not exist restore module class file');

				$oAdminController = getAdminController($output->data->getOriginModule());
				if(!method_exists($oAdminController, 'restoreTrash')) return new Object(-1, 'not exist restore method in module class file');

				$originObject = unserialize($output->data->getSerializedObject());
				$output = $oAdminController->restoreTrash($originObject);

				if(!$output->toBool())
				{
					$oDB->rollback();
					return new Object(-1, $output->message);
				}
			}

			// restore object delete in trash box
			if(!$this->_emptyTrash($trashSrlList)) {
				$oDB->rollback();
				return new Object(-1, $lang->fail_empty);
			}
			$oDB->commit();
		}

		$this->setMessage('success_restore', 'info');

		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispTrashAdminList');
		$this->setRedirectUrl($returnUrl);
	}

	/**
	 * Set trash list to Context
	 * @return void|Object
	 */
	function procTrashAdminGetList()
	{
		if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted');
		$trashSrls = Context::get('trash_srls');
		if($trashSrls) $trashSrlList = explode(',', $trashSrls);

		if(count($trashSrlList) > 0)
		{
			$oTrashModel = getModel('trash');
			$args = new stdClass();
			$args->trashSrl = $trashSrlList;
			$output = $oTrashModel->getTrashList($args);
			$trashList = $output->data;
		}
		else
		{
			global $lang;
			$trashList = array();
			$this->setMessage($lang->no_documents);
		}

		$oSecurity = new Security($trashList);
		$oSecurity->encodeHTML('..');
		$this->add('trash_list', $trashList);
	}

	/**
	 * empty trash
	 * @param array trashSrls
	 * @return bool
	 */
	function _emptyTrash($trashSrls)
	{
		if(!is_array($trashSrls)) return false;
		$args = new stdClass();
		$args->trashSrls = $trashSrls;
		$output = executeQuery('trash.deleteTrash', $args);
		if(!$output->toBool()) return false;

		return true;
	}
}
/* End of file trash.admin.controller.php */
/* Location: ./modules/trash/trash.admin.controller.php */

{'fraction_non_alphanumeric': 0.1766134373390242, 'fraction_numerical': 0.0033850908823312973, 'mean_word_length': 4.425149700598802, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 144, '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': '810240', 'n_tokens_mistral': 5362, 'n_tokens_neox': 4645, 'n_words': 848}