Completed
Push — dev ( 6f2681...eae16f )
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 %
Metric Value
dl 0
loc 24
rs 5.7377
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
		 *
43
		 * Appends javascript file references into the head, if needed
44
		 * @param array $context
45
		 */
46
		public function appendAssets(array $context) {
47
			// store the callback array locally
48
			$c = Administration::instance()->getPageCallback();
49
			
50
			// publish page
51
			if($c['driver'] == 'publish') {
52
				Administration::instance()->Page->addStylesheetToHead(
53
					URL . '/extensions/entry_relationship_field/assets/publish.entry_relationship_field.css',
54
					'screen',
55
					time() + 1,
56
					false
57
				);
58
				Administration::instance()->Page->addScriptToHead(
59
					URL . '/extensions/entry_relationship_field/assets/publish.entry_relationship_field.js',
60
					time(),
61
					false
62
				);
63
				
64
			} else if ($c['driver'] == 'blueprintssections') {
65
				Administration::instance()->Page->addStylesheetToHead(
66
					URL . '/extensions/entry_relationship_field/assets/section.entry_relationship_field.css',
67
					'screen',
68
					time() + 1,
69
					false
70
				);
71
				Administration::instance()->Page->addScriptToHead(
72
					URL . '/extensions/entry_relationship_field/assets/section.entry_relationship_field.js',
73
					time(),
74
					false
75
				);
76
			}
77
		}
78
79
		/* ********* INSTALL/UPDATE/UNINSTALL ******* */
80
81
		/**
82
		 * Creates the table needed for the settings of the field
83
		 */
84
		public function install() {
85
			General::realiseDirectory(WORKSPACE . '/er-templates');
86
			return FieldEntry_relationship::createFieldTable();
87
		}
88
89
		/**
90
		 * This method will update the extension according to the
91
		 * previous and current version parameters.
92
		 * @param string $previousVersion
93
		 */
94
		public function update($previousVersion = false) {
95
			$ret = true;
96
			
97
			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...
98
				$previousVersion = '0.0.1';
99
			}
100
			
101
			// less than 1.0.2
102
			if ($ret && version_compare($previousVersion, '1.0.2') == -1) {
103
				$ret = FieldEntry_relationship::update_102();
104
			}
105
			
106
			// less than 1.0.3
107
			if ($ret && version_compare($previousVersion, '1.0.3') == -1) {
108
				$ret = FieldEntry_relationship::update_103();
109
			}
110
			
111
			// less than 2.0.0
112
			if ($ret && version_compare($previousVersion, '2.0.0') == -1) {
113
				$ret = FieldEntry_relationship::update_200();
114
			}
115
			
116
			return $ret;
117
		}
118
119
		/**
120
		 * Drops the table needed for the settings of the field
121
		 */
122
		public function uninstall() {
123
			return FieldEntry_relationship::deleteFieldTable();
124
		}
125
126
	}