Passed
Pull Request — master (#105)
by
unknown
01:39
created

elkarte1_1::getTableTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @name      OpenImporter
4
 * @copyright OpenImporter contributors
5
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
6
 *
7
 * @version 1.0 Alpha
8
 */
9
10
/**
11
 * Class elkarte1_1
12
 */
13
 
14
class elkarte1_1 extends Importers\AbstractSourceImporter
15
{
16
	protected $setting_file = '/Settings.php';
17
18
	protected $smf_attach_folders = null;
19
20
21
	public function getName()
22
	{
23
		return 'elkarte1_1';
24
	}
25
26
	public function getVersion()
27
	{
28
		return 'SMF 2.0';
29
	}
30
31
	public function setDefines()
32
	{
33
34
	}
35
36
	public function getPrefix()
37
	{
38
		$db_name = $this->getDbName();
39
		$db_prefix = $this->fetchSetting('db_prefix');
40
41
		return '`' . $db_name . '`.' . $db_prefix;
42
	}
43
44
	public function getDbName()
45
	{
46
		return $this->fetchSetting('db_name');
47
	}
48
49
	public function getTableTest()
50
	{
51
		return 'members';
52
	}
53
54
	protected function fetchSetting($name)
55
	{
56
		static $content = null;
57
58
		if ($content === null)
59
			$content = file_get_contents($this->path . '/Settings.php');
60
61
		$match = array();
62
		preg_match('~\$' . $name . '\s*=\s*\'(.*?)\';~', $content, $match);
63
64
		return isset($match[1]) ? $match[1] : '';
65
	}
66
67
	/**
68
	 * Read the attachment directory structure from the source db
69
	 *
70
	 * @return array|null
71
	 */
72
	public function getAttachmentDirs()
73
	{
74
		if ($this->smf_attach_folders === null)
75
		{
76
			$from_prefix = $this->config->from_prefix;
77
78
			$request = $this->db->query("
79
				SELECT value
80
				FROM {$from_prefix}settings
81
				WHERE variable='attachmentUploadDir';");
82
			list ($smf_attachments_dir) = $this->db->fetch_row($request);
83
84
			$this->smf_attach_folders = @unserialize($smf_attachments_dir);
85
86
			if (!is_array($this->smf_attach_folders))
87
				$this->smf_attach_folders = array(1 => $smf_attachments_dir);
88
		}
89
90
		return $this->smf_attach_folders;
91
	}
92
93
94
95
}
96
97
/**
98
 * Copy attachments from the source to our destination
99
 *
100
 * @param array $row
101
 * @param \OpenImporter\Database $db
102
 * @param string $from_prefix
103
 * @param string $attachmentUploadDir
104
 */
105
function moveAttachment(&$row, $db, $from_prefix, $attachmentUploadDir)
0 ignored issues
show
Best Practice introduced by
The function moveAttachment() has been defined more than once; this definition is ignored, only the first definition in importer/Importers/elkarte1.0/smf1-1_importer.php (L83-147) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
106
{
107
	static $smf_folders = null;
108
	
109
110
	// We need to know where the attachments are located
111
	if ($smf_folders === null)
112
	{
113
		$request = $db->query("
114
			SELECT value
115
			FROM {$from_prefix}settings
116
			WHERE variable='attachmentUploadDir';");
117
		list ($smf_attachments_dir) = $db->fetch_row($request);
118
119
		$smf_folders = @unserialize($smf_attachments_dir);
120
121
	//	print_r($smf_folders);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
122
123
		if (!is_array($smf_folders))
124
			$smf_folders = array(1 => $smf_attachments_dir);
125
	}
126
127
128
129
130
	// If something is broken, better try to account for it as well.
131
	if (isset($smf_folders[$row['id_folder']]))
132
		$smf_attachments_dir = $smf_folders[$row['id_folder']];
133
	else
134
		$smf_attachments_dir = $smf_folders[1];
135
136
	// Missing the file hash ... create one
137
	if (empty($row['file_hash']))
138
	{
139
		$row['file_hash'] = createAttachmentFileHash($row['filename']);
140
		$source_file = $row['filename'];
141
	}
142
	else
143
		$source_file = $row['id_attach'] . '_' . $row['file_hash'];
144
145
	// Copy it over
146
	if (file_exists($smf_attachments_dir . '/' . $source_file . '.elk'))
147
	copy_file($smf_attachments_dir . '/' . $source_file . '.elk', $attachmentUploadDir . '/' . $row['id_attach'] . '_' . $row['file_hash']);
148
	
149
	if (file_exists($smf_attachments_dir . '/' . $source_file . '.elk_thumb'))
150
	copy_file($smf_attachments_dir . '/' . $source_file . '.elk_thumb', $attachmentUploadDir . '/' . $row['id_attach'] . '_' . $row['file_hash'] . '_thumb');	
151
}