Completed
Push — dev ( 5bf8b4...6f87eb )
by Nicolas
01:47
created

extension_entry_relationship_field::update()   C

Complexity

Conditions 8
Paths 16

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 5.7377
c 0
b 0
f 0
cc 8
eloc 11
nc 16
nop 1
1
<?php
2
	/*
3
	Copyight: Deux Huit Huit 2014
4
	LICENCE: MIT http://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
	
11
	/**
12
	 *
13
	 * @author Deux Huit Huit
14
	 * https://deuxhuithuit.com/
15
	 *
16
	 */
17
	class extension_entry_relationship_field extends Extension {
18
19
		/**
20
		 * Name of the extension
21
		 * @var string
22
		 */
23
		const EXT_NAME = 'Entry Relationship Field';
24
		
25
		/**
26
		 * Symphony utility function that permits to
27
		 * implement the Observer/Observable pattern.
28
		 * We register here delegate that will be fired by Symphony
29
		 */
30
31
		public function getSubscribedDelegates(){
32
			return array(
33
				array(
34
					'page' => '/backend/',
35
					'delegate' => 'InitaliseAdminPageHead',
36
					'callback' => 'appendAssets'
37
				)
38
			);
39
		}
40
41
		/**
42
		 * Delegate fired to add a link to Cache Management
43
		 */
44
		public function fetchNavigation() {
45
			if (is_callable(array('Symphony', 'Author'))) {
46
				$author = Symphony::Author();
47
			} else {
48
				$author = Administration::instance()->Author;
49
			}
50
			
51
			// Work around single group limit in nav
52
			$group = $author->isDeveloper() ? 'developer' : 'manager';
53
			
54
			return array(
55
					array (
56
						'location' => __('System'),
57
						'name' => __('ERF Clean up'),
58
						'link' => 'cleanup',
59
						'limit' => $group,
60
					) // nav group
61
			); // nav
62
		}
63
64
		/**
65
		 *
66
		 * Appends javascript file references into the head, if needed
67
		 * @param array $context
68
		 */
69
		public function appendAssets(array $context) {
70
			// store the callback array locally
71
			$c = Administration::instance()->getPageCallback();
72
			
73
			// publish page
74
			if($c['driver'] == 'publish') {
75
				Administration::instance()->Page->addStylesheetToHead(
76
					URL . '/extensions/entry_relationship_field/assets/publish.entry_relationship_field.css',
77
					'screen',
78
					time() + 1,
79
					false
80
				);
81
				Administration::instance()->Page->addScriptToHead(
82
					URL . '/extensions/entry_relationship_field/assets/publish.entry_relationship_field.js',
83
					10,
84
					false
85
				);
86
				
87
			} else if ($c['driver'] == 'blueprintssections') {
88
				Administration::instance()->Page->addStylesheetToHead(
89
					URL . '/extensions/entry_relationship_field/assets/section.entry_relationship_field.css',
90
					'screen',
91
					time() + 1,
92
					false
93
				);
94
				Administration::instance()->Page->addScriptToHead(
95
					URL . '/extensions/entry_relationship_field/assets/section.entry_relationship_field.js',
96
					time(),
97
					false
98
				);
99
			}
100
		}
101
102
		/* ********* INSTALL/UPDATE/UNINSTALL ******* */
103
104
		/**
105
		 * Creates the table needed for the settings of the field
106
		 */
107
		public function install() {
108
			General::realiseDirectory(WORKSPACE . '/er-templates');
109
			return FieldEntry_relationship::createFieldTable();
110
		}
111
112
		/**
113
		 * This method will update the extension according to the
114
		 * previous and current version parameters.
115
		 * @param string $previousVersion
116
		 */
117
		public function update($previousVersion = false) {
118
			$ret = true;
119
			
120
			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...
121
				$previousVersion = '0.0.1';
122
			}
123
			
124
			// less than 1.0.2
125
			if ($ret && version_compare($previousVersion, '1.0.2', '<')) {
126
				$ret = FieldEntry_relationship::update_102();
127
			}
128
			
129
			// less than 1.0.3
130
			if ($ret && version_compare($previousVersion, '1.0.3', '<')) {
131
				$ret = FieldEntry_relationship::update_103();
132
			}
133
			
134
			// less than 2.0.0
135
			if ($ret && version_compare($previousVersion, '2.0.0', '<')) {
136
				$ret = FieldEntry_relationship::update_200();
137
			}
138
			
139
			return $ret;
140
		}
141
142
		/**
143
		 * Drops the table needed for the settings of the field
144
		 */
145
		public function uninstall() {
146
			return FieldEntry_relationship::deleteFieldTable();
147
		}
148
149
	}