Project

General

Profile

1
<?php
2
/**
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

    
19
/**
20
 * Reorg.php
21
 *
22
 * @category     Module
23
 * @package      Module_news
24
 * @author       Werner v.d.Decken <wkl@isteam.de>
25
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
26
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
27
 * @version      0.0.1
28
 * @revision     $Revision: $
29
 * @link         $HeadURL: $
30
 * @lastmodified $Date: $
31
 * @since        File available since 17.01.2013
32
 * @description  Reorganisation jobs for the 'news' module
33
 */
34

    
35
class m_news_Reorg {
36

    
37
	private $_aSys = array();
38
/**
39
 * Execute reorganisation
40
 * @return string all occured messages 
41
 */
42
	public function execute() 
43
	{
44
		$sOutput = null;
45
		if(class_exists('WbAdaptor')) {
46
			$this->_aSys['TablePrefix'] = WbAdaptor::getInstance()->TablePrefix;
47
			$this->_aSys['AppPath'] = WbAdaptor::getInstance()->AppPath;
48
			$this->_aSys['PagesDir'] = WbAdaptor::getInstance()->PagesDir;
49
			$this->_aSys['PageExtension'] = WbAdaptor::getInstance()->PageExtension;
50
			$sOutput = $this->createAccessFiles();
51
		}
52
		// add here the requests for additional reorg methods
53
		return $sOutput;
54
	}
55
/**
56
 * Creates all Accessfiles from DB
57
 * @return string all occured messages 
58
 */
59
	protected function createAccessFiles()
60
	{
61
		$count = 0;
62
		$aReturnMsg = array();
63
		$sql  = 'SELECT `page_id`,`post_id`,`section_id`,`link` ';
64
		$sql .= 'FROM `'.$this->_aSys['TablePrefix'].'mod_news_posts`';
65
		$sql .= 'WHERE `link` != \'\'';
66
		if(($oPosts = WbDatabase::getInstance()->query($sql))) {
67
			while($aPost = $oPosts->fetchRow(MYSQL_ASSOC))
68
			{
69
				$sAccessFile = $this->_aSys['AppPath'].$this->_aSys['PagesDir']
70
				               . trim(str_replace('\\', '/', $aPost['link']), '/')
71
				               . $this->_aSys['PageExtension'];
72
				$aOptionalCommand = array(
73
					'$section_id   = '.$aPost['section_id'].';',
74
					'$post_section = '.$aPost['section_id'].';',
75
					'$post_id      = '.$aPost['post_id'].';'
76
				);
77
				if(create_access_file($sAccessFile, $aPost['page_id'], 0, $aOptionalCommand)){
78
					$count++;	
79
				} else {
80
					$aReturnMsg[] = 'Can\'t create '.$sAccessFile;	
81
				}
82
			}
83
			$aReturnMsg[] = 'Number of new created access files: '.$count;
84
		}
85
		return $aReturnMsg;
86
	}
87
	// add here some additional reorg methods **************************************** *//
88
} // end of class Reorg
(1-1/33)