Completed
Push — master ( 2867c5...18d669 )
by Nicolas
08:20 queued 04:11
created

extension_entry_relationship_field::update()   D

Complexity

Conditions 14
Paths 128

Size

Total Lines 39
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 4.7877
c 0
b 0
f 0
cc 14
eloc 17
nc 128
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
	/*
3
	Copyight: Deux Huit Huit 2014
4
	LICENCE: MIT https://deuxhuithuit.mit-license.org
5
	*/
6
	
7
	if(!defined("__IN_SYMPHONY__")) die("<h2>Error</h2><p>You cannot directly access this file</p>");
8
	
9
	require_once(EXTENSIONS . '/entry_relationship_field/fields/field.entry_relationship.php');
10
	require_once(EXTENSIONS . '/entry_relationship_field/fields/field.reverse_relationship.php');
11
	
12
	/**
13
	 *
14
	 * @author Deux Huit Huit
15
	 * https://deuxhuithuit.com/
16
	 *
17
	 */
18
	class extension_entry_relationship_field extends Extension {
19
20
		/**
21
		 * Name of the extension
22
		 * @var string
23
		 */
24
		const EXT_NAME = 'Entry Relationship Field';
25
		
26
		/**
27
		 * Symphony utility function that permits to
28
		 * implement the Observer/Observable pattern.
29
		 * We register here delegate that will be fired by Symphony
30
		 */
31
32
		public function getSubscribedDelegates(){
33
			return array(
34
				array(
35
					'page' => '/backend/',
36
					'delegate' => 'InitaliseAdminPageHead',
37
					'callback' => 'appendAssets'
38
				)
39
			);
40
		}
41
42
		/**
43
		 * Delegate fired to add a link to Cache Management
44
		 */
45
		public function fetchNavigation() {
46
			if (is_callable(array('Symphony', 'Author'))) {
47
				$author = Symphony::Author();
48
			} else {
49
				$author = Administration::instance()->Author;
50
			}
51
			
52
			// Work around single group limit in nav
53
			$group = $author->isDeveloper() ? 'developer' : 'manager';
54
			
55
			return array(
56
					array (
57
						'location' => __('System'),
58
						'name' => __('ERF Clean up'),
59
						'link' => 'cleanup',
60
						'limit' => $group,
61
					) // nav group
62
			); // nav
63
		}
64
65
		/**
66
		 *
67
		 * Appends javascript file references into the head, if needed
68
		 * @param array $context
69
		 */
70
		public function appendAssets(array $context) {
71
			// store the callback array locally
72
			$c = Administration::instance()->getPageCallback();
73
			
74
			// publish page
75
			if($c['driver'] == 'publish') {
76
				Administration::instance()->Page->addStylesheetToHead(
77
					URL . '/extensions/entry_relationship_field/assets/publish.entry_relationship_field.css',
78
					'screen',
79
					time() + 1,
80
					false
81
				);
82
				Administration::instance()->Page->addScriptToHead(
83
					URL . '/extensions/entry_relationship_field/assets/publish.entry_relationship_field.js',
84
					10,
85
					false
86
				);
87
				
88
			} else if ($c['driver'] == 'blueprintssections') {
89
				Administration::instance()->Page->addStylesheetToHead(
90
					URL . '/extensions/entry_relationship_field/assets/section.entry_relationship_field.css',
91
					'screen',
92
					time() + 1,
93
					false
94
				);
95
				Administration::instance()->Page->addScriptToHead(
96
					URL . '/extensions/entry_relationship_field/assets/section.entry_relationship_field.js',
97
					time(),
98
					false
99
				);
100
			}
101
		}
102
103
		/* ********* INSTALL/UPDATE/UNINSTALL ******* */
104
105
		/**
106
		 * Creates the table needed for the settings of the field
107
		 */
108
		public function install() {
109
			General::realiseDirectory(WORKSPACE . '/er-templates');
110
			return FieldEntry_Relationship::createFieldTable() && FieldReverse_Relationship::createFieldTable();
111
		}
112
113
		/**
114
		 * This method will update the extension according to the
115
		 * previous and current version parameters.
116
		 * @param string $previousVersion
117
		 */
118
		public function update($previousVersion = false) {
119
			$ret = true;
120
			
121
			if (!$previousVersion) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $previousVersion of type false|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
122
				$previousVersion = '0.0.1';
123
			}
124
			
125
			// less than 1.0.2
126
			if ($ret && version_compare($previousVersion, '1.0.2', '<')) {
127
				$ret = FieldEntry_Relationship::update_102();
128
			}
129
			
130
			// less than 1.0.3
131
			if ($ret && version_compare($previousVersion, '1.0.3', '<')) {
132
				$ret = FieldEntry_Relationship::update_103();
133
			}
134
			
135
			// less than 2.0.0.beta5
136
			if ($ret && version_compare($previousVersion, '2.0.0.beta5', '<')) {
137
				$ret = FieldEntry_Relationship::update_200();
138
			}
139
			
140
			// less than 2.0.0.beta6
141
			if ($ret && version_compare($previousVersion, '2.0.0.beta6', '<')) {
142
				$ret = FieldReverse_Relationship::update_200();
143
			}
144
			
145
			// less than 2.0.0.beta8
146
			if ($ret && version_compare($previousVersion, '2.0.0.beta8', '<')) {
147
				$ret = FieldEntry_Relationship::update_2008();
148
			}
149
			
150
			// less than 2.1.0
151
			if ($ret && version_compare($previousVersion, '2.1.0', '<')) {
152
				$ret = FieldReverse_Relationship::update_210();
153
			}
154
			
155
			return $ret;
156
		}
157
158
		/**
159
		 * Drops the table needed for the settings of the field
160
		 */
161
		public function uninstall() {
162
			return FieldEntry_Relationship::deleteFieldTable() && FieldReverse_Relationship::deleteFieldTable();
163
		}
164
165
	}