Complex classes like Versioned often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Versioned, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Versioned extends DataExtension implements TemplateGlobalProvider { |
||
17 | /** |
||
18 | * An array of possible stages. |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $stages; |
||
22 | |||
23 | /** |
||
24 | * The 'default' stage. |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $defaultStage; |
||
28 | |||
29 | /** |
||
30 | * The 'live' stage. |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $liveStage; |
||
34 | |||
35 | /** |
||
36 | * The default reading mode |
||
37 | */ |
||
38 | const DEFAULT_MODE = 'Stage.Live'; |
||
39 | |||
40 | /** |
||
41 | * A version that a DataObject should be when it is 'migrating', |
||
42 | * that is, when it is in the process of moving from one stage to another. |
||
43 | * @var string |
||
44 | */ |
||
45 | public $migratingVersion; |
||
46 | |||
47 | /** |
||
48 | * A cache used by get_versionnumber_by_stage(). |
||
49 | * Clear through {@link flushCache()}. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected static $cache_versionnumber; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | protected static $reading_mode = null; |
||
59 | |||
60 | /** |
||
61 | * @var Boolean Flag which is temporarily changed during the write() process |
||
62 | * to influence augmentWrite() behaviour. If set to TRUE, no new version will be created |
||
63 | * for the following write. Needs to be public as other classes introspect this state |
||
64 | * during the write process in order to adapt to this versioning behaviour. |
||
65 | */ |
||
66 | public $_nextWriteWithoutVersion = false; |
||
67 | |||
68 | /** |
||
69 | * Additional database columns for the new |
||
70 | * "_versions" table. Used in {@link augmentDatabase()} |
||
71 | * and all Versioned calls extending or creating |
||
72 | * SELECT statements. |
||
73 | * |
||
74 | * @var array $db_for_versions_table |
||
75 | */ |
||
76 | private static $db_for_versions_table = array( |
||
77 | "RecordID" => "Int", |
||
78 | "Version" => "Int", |
||
79 | "WasPublished" => "Boolean", |
||
80 | "AuthorID" => "Int", |
||
81 | "PublisherID" => "Int" |
||
82 | ); |
||
83 | |||
84 | /** |
||
85 | * @var array |
||
86 | */ |
||
87 | private static $db = array( |
||
88 | 'Version' => 'Int' |
||
89 | ); |
||
90 | |||
91 | /** |
||
92 | * Used to enable or disable the prepopulation of the version number cache. |
||
93 | * Defaults to true. |
||
94 | * |
||
95 | * @var boolean |
||
96 | */ |
||
97 | private static $prepopulate_versionnumber_cache = true; |
||
98 | |||
99 | /** |
||
100 | * Keep track of the archive tables that have been created. |
||
101 | * |
||
102 | * @var array |
||
103 | */ |
||
104 | private static $archive_tables = array(); |
||
105 | |||
106 | /** |
||
107 | * Additional database indexes for the new |
||
108 | * "_versions" table. Used in {@link augmentDatabase()}. |
||
109 | * |
||
110 | * @var array $indexes_for_versions_table |
||
111 | */ |
||
112 | private static $indexes_for_versions_table = array( |
||
113 | 'RecordID_Version' => '("RecordID","Version")', |
||
114 | 'RecordID' => true, |
||
115 | 'Version' => true, |
||
116 | 'AuthorID' => true, |
||
117 | 'PublisherID' => true, |
||
118 | ); |
||
119 | |||
120 | |||
121 | /** |
||
122 | * An array of DataObject extensions that may require versioning for extra tables |
||
123 | * The array value is a set of suffixes to form these table names, assuming a preceding '_'. |
||
124 | * E.g. if Extension1 creates a new table 'Class_suffix1' |
||
125 | * and Extension2 the tables 'Class_suffix2' and 'Class_suffix3': |
||
126 | * |
||
127 | * $versionableExtensions = array( |
||
128 | * 'Extension1' => 'suffix1', |
||
129 | * 'Extension2' => array('suffix2', 'suffix3'), |
||
130 | * ); |
||
131 | * |
||
132 | * This can also be manipulated by updating the current loaded config |
||
133 | * |
||
134 | * SiteTree: |
||
135 | * versionableExtensions: |
||
136 | * - Extension1: |
||
137 | * - suffix1 |
||
138 | * - suffix2 |
||
139 | * - Extension2: |
||
140 | * - suffix1 |
||
141 | * - suffix2 |
||
142 | * |
||
143 | * or programatically: |
||
144 | * |
||
145 | * Config::inst()->update($this->owner->class, 'versionableExtensions', |
||
146 | * array('Extension1' => 'suffix1', 'Extension2' => array('suffix2', 'suffix3'))); |
||
147 | * |
||
148 | * |
||
149 | * Make sure your extension has a static $enabled-property that determines if it is |
||
150 | * processed by Versioned. |
||
151 | * |
||
152 | * @var array |
||
153 | */ |
||
154 | protected static $versionableExtensions = array('Translatable' => 'lang'); |
||
155 | |||
156 | /** |
||
157 | * Permissions necessary to view records outside of the live stage (e.g. archive / draft stage). |
||
158 | * |
||
159 | * @config |
||
160 | * @var array |
||
161 | */ |
||
162 | private static $non_live_permissions = array('CMS_ACCESS_LeftAndMain', 'CMS_ACCESS_CMSMain', 'VIEW_DRAFT_CONTENT'); |
||
163 | |||
164 | /** |
||
165 | * List of relationships on this object that are "owned" by this object. |
||
166 | * Owership in the context of versioned objects is a relationship where |
||
167 | * the publishing of owning objects requires the publishing of owned objects. |
||
168 | * |
||
169 | * E.g. A page owns a set of banners, as in order for the page to be published, all |
||
170 | * banners on this page must also be published for it to be visible. |
||
171 | * |
||
172 | * Typically any object and its owned objects should be visible in the same edit view. |
||
173 | * E.g. a page and {@see GridField} of banners. |
||
174 | * |
||
175 | * Page hierarchy is typically not considered an ownership relationship. |
||
176 | * |
||
177 | * Ownership is recursive; If A owns B and B owns C then A owns C. |
||
178 | * |
||
179 | * @config |
||
180 | * @var array List of has_many or many_many relationships owned by this object. |
||
181 | */ |
||
182 | private static $owns = array(); |
||
183 | |||
184 | /** |
||
185 | * Opposing relationship to owns config; Represents the objects which |
||
186 | * own the current object. |
||
187 | * |
||
188 | * @var array |
||
189 | */ |
||
190 | private static $owned_by = array(); |
||
191 | |||
192 | /** |
||
193 | * Reset static configuration variables to their default values. |
||
194 | */ |
||
195 | public static function reset() { |
||
200 | |||
201 | /** |
||
202 | * Construct a new Versioned object. |
||
203 | * |
||
204 | * @var array $stages The different stages the versioned object can be. |
||
205 | * The first stage is considered the 'default' stage, the last stage is |
||
206 | * considered the 'live' stage. |
||
207 | */ |
||
208 | public function __construct($stages = array('Stage','Live')) { |
||
209 | parent::__construct(); |
||
210 | |||
211 | if(!is_array($stages)) { |
||
212 | $stages = func_get_args(); |
||
213 | } |
||
214 | |||
215 | $this->stages = $stages; |
||
216 | $this->defaultStage = reset($stages); |
||
217 | $this->liveStage = array_pop($stages); |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * Amend freshly created DataQuery objects with versioned-specific |
||
222 | * information. |
||
223 | * |
||
224 | * @param SQLSelect |
||
225 | * @param DataQuery |
||
226 | */ |
||
227 | public function augmentDataQueryCreation(SQLSelect &$query, DataQuery &$dataQuery) { |
||
238 | |||
239 | |||
240 | public function updateInheritableQueryParams(&$params) { |
||
247 | |||
248 | /** |
||
249 | * Augment the the SQLSelect that is created by the DataQuery |
||
250 | * |
||
251 | * @param SQLSelect $query |
||
252 | * @param DataQuery $dataQuery |
||
253 | * @throws InvalidArgumentException |
||
254 | */ |
||
255 | public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { |
||
396 | |||
397 | /** |
||
398 | * Determine if the given versioned table is a part of the sub-tree of the current dataobject |
||
399 | * This helps prevent rewriting of other tables that get joined in, in particular, many_many tables |
||
400 | * |
||
401 | * @param string $table |
||
402 | * @return bool True if this table should be versioned |
||
403 | */ |
||
404 | protected function isTableVersioned($table) { |
||
411 | |||
412 | /** |
||
413 | * For lazy loaded fields requiring extra sql manipulation, ie versioning. |
||
414 | * |
||
415 | * @param SQLSelect $query |
||
416 | * @param DataQuery $dataQuery |
||
417 | * @param DataObject $dataObject |
||
418 | */ |
||
419 | public function augmentLoadLazyFields(SQLSelect &$query, DataQuery &$dataQuery = null, $dataObject) { |
||
439 | |||
440 | |||
441 | /** |
||
442 | * Called by {@link SapphireTest} when the database is reset. |
||
443 | * |
||
444 | * @todo Reduce the coupling between this and SapphireTest, somehow. |
||
445 | */ |
||
446 | public static function on_db_reset() { |
||
457 | |||
458 | public function augmentDatabase() { |
||
620 | |||
621 | /** |
||
622 | * Helper for augmentDatabase() to find unique indexes and convert them to non-unique |
||
623 | * |
||
624 | * @param array $indexes The indexes to convert |
||
625 | * @return array $indexes |
||
626 | */ |
||
627 | private function uniqueToIndex($indexes) { |
||
649 | |||
650 | /** |
||
651 | * Generates a ($table)_version DB manipulation and injects it into the current $manipulation |
||
652 | * |
||
653 | * @param array $manipulation Source manipulation data |
||
654 | * @param string $table Name of table |
||
655 | * @param int $recordID ID of record to version |
||
656 | */ |
||
657 | protected function augmentWriteVersioned(&$manipulation, $table, $recordID) { |
||
710 | |||
711 | /** |
||
712 | * Rewrite the given manipulation to update the selected (non-default) stage |
||
713 | * |
||
714 | * @param array $manipulation Source manipulation data |
||
715 | * @param string $table Name of table |
||
716 | * @param int $recordID ID of record to version |
||
717 | */ |
||
718 | protected function augmentWriteStaged(&$manipulation, $table, $recordID) { |
||
731 | |||
732 | |||
733 | public function augmentWrite(&$manipulation) { |
||
804 | |||
805 | /** |
||
806 | * Perform a write without affecting the version table. |
||
807 | * On objects without versioning. |
||
808 | * |
||
809 | * @return int The ID of the record |
||
810 | */ |
||
811 | public function writeWithoutVersion() { |
||
816 | |||
817 | /** |
||
818 | * |
||
819 | */ |
||
820 | public function onAfterWrite() { |
||
823 | |||
824 | /** |
||
825 | * If a write was skipped, then we need to ensure that we don't leave a |
||
826 | * migrateVersion() value lying around for the next write. |
||
827 | */ |
||
828 | public function onAfterSkippedWrite() { |
||
831 | |||
832 | /** |
||
833 | * Find all objects owned by the current object. |
||
834 | * Note that objects will only be searched in the same stage as the given record. |
||
835 | * |
||
836 | * @param bool $recursive True if recursive |
||
837 | * @param ArrayList $list Optional list to add items to |
||
838 | * @return ArrayList list of objects |
||
839 | */ |
||
840 | public function findOwned($recursive = true, $list = null) |
||
845 | |||
846 | /** |
||
847 | * Find objects which own this object. |
||
848 | * Note that objects will only be searched in the same stage as the given record. |
||
849 | * |
||
850 | * @param bool $recursive True if recursive |
||
851 | * @param ArrayList $list Optional list to add items to |
||
852 | * @return ArrayList list of objects |
||
853 | */ |
||
854 | public function findOwners($recursive = true, $list = null) |
||
859 | |||
860 | /** |
||
861 | * Find objects in the given relationships, merging them into the given list |
||
862 | * |
||
863 | * @param array $source Config property to extract relationships from |
||
864 | * @param bool $recursive True if recursive |
||
865 | * @param ArrayList $list Optional list to add items to |
||
866 | * @return ArrayList The list |
||
867 | */ |
||
868 | public function findRelatedObjects($source, $recursive = true, $list = null) |
||
920 | |||
921 | /** |
||
922 | * This function should return true if the current user can publish this record. |
||
923 | * It can be overloaded to customise the security model for an application. |
||
924 | * |
||
925 | * Denies permission if any of the following conditions is true: |
||
926 | * - canPublish() on any extension returns false |
||
927 | * - canEdit() returns false |
||
928 | * |
||
929 | * @param Member $member |
||
930 | * @return bool True if the current user can publish this record. |
||
931 | */ |
||
932 | public function canPublish($member = null) { |
||
955 | |||
956 | /** |
||
957 | * Check if the current user can delete this record from live |
||
958 | * |
||
959 | * @param null $member |
||
960 | * @return mixed |
||
961 | */ |
||
962 | public function canUnpublish($member = null) { |
||
985 | |||
986 | /** |
||
987 | * Check if the current user is allowed to archive this record. |
||
988 | * If extended, ensure that both canDelete and canUnpublish are extended also |
||
989 | * |
||
990 | * @param Member $member |
||
991 | * @return bool |
||
992 | */ |
||
993 | public function canArchive($member = null) { |
||
1025 | |||
1026 | /** |
||
1027 | * Extend permissions to include additional security for objects that are not published to live. |
||
1028 | * |
||
1029 | * @param Member $member |
||
1030 | * @return bool|null |
||
1031 | */ |
||
1032 | public function canView($member = null) { |
||
1038 | |||
1039 | /** |
||
1040 | * Determine if there are any additional restrictions on this object for the given reading version. |
||
1041 | * |
||
1042 | * Override this in a subclass to customise any additional effect that Versioned applies to canView. |
||
1043 | * |
||
1044 | * This is expected to be called by canView, and thus is only responsible for denying access if |
||
1045 | * the default canView would otherwise ALLOW access. Thus it should not be called in isolation |
||
1046 | * as an authoritative permission check. |
||
1047 | * |
||
1048 | * This has the following extension points: |
||
1049 | * - canViewDraft is invoked if Mode = stage and Stage = stage |
||
1050 | * - canViewArchived is invoked if Mode = archive |
||
1051 | * |
||
1052 | * @param Member $member |
||
1053 | * @return bool False is returned if the current viewing mode denies visibility |
||
1054 | */ |
||
1055 | public function canViewVersioned($member = null) { |
||
1092 | |||
1093 | /** |
||
1094 | * Determines canView permissions for the latest version of this object on a specific stage. |
||
1095 | * Usually the stage is read from {@link Versioned::current_stage()}. |
||
1096 | * |
||
1097 | * This method should be invoked by user code to check if a record is visible in the given stage. |
||
1098 | * |
||
1099 | * This method should not be called via ->extend('canViewStage'), but rather should be |
||
1100 | * overridden in the extended class. |
||
1101 | * |
||
1102 | * @param string $stage |
||
1103 | * @param Member $member |
||
1104 | * @return bool |
||
1105 | */ |
||
1106 | public function canViewStage($stage = 'Live', $member = null) { |
||
1115 | |||
1116 | /** |
||
1117 | * Determine if a table is supporting the Versioned extensions (e.g. |
||
1118 | * $table_versions does exists). |
||
1119 | * |
||
1120 | * @param string $table Table name |
||
1121 | * @return boolean |
||
1122 | */ |
||
1123 | public function canBeVersioned($table) { |
||
1128 | |||
1129 | /** |
||
1130 | * Check if a certain table has the 'Version' field. |
||
1131 | * |
||
1132 | * @param string $table Table name |
||
1133 | * |
||
1134 | * @return boolean Returns false if the field isn't in the table, true otherwise |
||
1135 | */ |
||
1136 | public function hasVersionField($table) { |
||
1147 | |||
1148 | /** |
||
1149 | * @param string $table |
||
1150 | * |
||
1151 | * @return string |
||
1152 | */ |
||
1153 | public function extendWithSuffix($table) { |
||
1170 | |||
1171 | /** |
||
1172 | * Get the latest published DataObject. |
||
1173 | * |
||
1174 | * @return DataObject |
||
1175 | */ |
||
1176 | public function latestPublished() { |
||
1189 | |||
1190 | /** |
||
1191 | * Provides a simple doPublish action for Versioned dataobjects |
||
1192 | * |
||
1193 | * @return bool True if publish was successful |
||
1194 | */ |
||
1195 | public function doPublish() { |
||
1203 | |||
1204 | |||
1205 | |||
1206 | /** |
||
1207 | * Removes the record from both live and stage |
||
1208 | * |
||
1209 | * @return bool Success |
||
1210 | */ |
||
1211 | public function doArchive() { |
||
1224 | |||
1225 | /** |
||
1226 | * Removes this record from the live site |
||
1227 | * |
||
1228 | * @return bool Flag whether the unpublish was successful |
||
1229 | * |
||
1230 | * @uses SiteTreeExtension->onBeforeUnpublish() |
||
1231 | * @uses SiteTreeExtension->onAfterUnpublish() |
||
1232 | */ |
||
1233 | public function doUnpublish() { |
||
1260 | |||
1261 | /** |
||
1262 | * Move a database record from one stage to the other. |
||
1263 | * |
||
1264 | * @param int|string $fromStage Place to copy from. Can be either a stage name or a version number. |
||
1265 | * @param string $toStage Place to copy to. Must be a stage name. |
||
1266 | * @param bool $createNewVersion Set this to true to create a new version number. |
||
1267 | * By default, the existing version number will be copied over. |
||
1268 | */ |
||
1269 | public function publish($fromStage, $toStage, $createNewVersion = false) { |
||
1328 | |||
1329 | /** |
||
1330 | * Set the migrating version. |
||
1331 | * |
||
1332 | * @param string $version The version. |
||
1333 | */ |
||
1334 | public function migrateVersion($version) { |
||
1337 | |||
1338 | /** |
||
1339 | * Compare two stages to see if they're different. |
||
1340 | * |
||
1341 | * Only checks the version numbers, not the actual content. |
||
1342 | * |
||
1343 | * @param string $stage1 The first stage to check. |
||
1344 | * @param string $stage2 |
||
1345 | */ |
||
1346 | public function stagesDiffer($stage1, $stage2) { |
||
1367 | |||
1368 | /** |
||
1369 | * @param string $filter |
||
1370 | * @param string $sort |
||
1371 | * @param string $limit |
||
1372 | * @param string $join Deprecated, use leftJoin($table, $joinClause) instead |
||
1373 | * @param string $having |
||
1374 | */ |
||
1375 | public function Versions($filter = "", $sort = "", $limit = "", $join = "", $having = "") { |
||
1378 | |||
1379 | /** |
||
1380 | * Return a list of all the versions available. |
||
1381 | * |
||
1382 | * @param string $filter |
||
1383 | * @param string $sort |
||
1384 | * @param string $limit |
||
1385 | * @param string $join Deprecated, use leftJoin($table, $joinClause) instead |
||
1386 | * @param string $having |
||
1387 | * @return ArrayList |
||
1388 | */ |
||
1389 | public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $having = "") { |
||
1432 | |||
1433 | /** |
||
1434 | * Compare two version, and return the diff between them. |
||
1435 | * |
||
1436 | * @param string $from The version to compare from. |
||
1437 | * @param string $to The version to compare to. |
||
1438 | * |
||
1439 | * @return DataObject |
||
1440 | */ |
||
1441 | public function compareVersions($from, $to) { |
||
1449 | |||
1450 | /** |
||
1451 | * Return the base table - the class that directly extends DataObject. |
||
1452 | * |
||
1453 | * @param string $stage |
||
1454 | * @return string |
||
1455 | */ |
||
1456 | public function baseTable($stage = null) { |
||
1466 | |||
1467 | //-----------------------------------------------------------------------------------------------// |
||
1468 | |||
1469 | |||
1470 | /** |
||
1471 | * Determine if the current user is able to set the given site stage / archive |
||
1472 | * |
||
1473 | * @param SS_HTTPRequest $request |
||
1474 | * @return bool |
||
1475 | */ |
||
1476 | public static function can_choose_site_stage($request) { |
||
1489 | |||
1490 | /** |
||
1491 | * Choose the stage the site is currently on. |
||
1492 | * |
||
1493 | * If $_GET['stage'] is set, then it will use that stage, and store it in |
||
1494 | * the session. |
||
1495 | * |
||
1496 | * if $_GET['archiveDate'] is set, it will use that date, and store it in |
||
1497 | * the session. |
||
1498 | * |
||
1499 | * If neither of these are set, it checks the session, otherwise the stage |
||
1500 | * is set to 'Live'. |
||
1501 | */ |
||
1502 | public static function choose_site_stage() { |
||
1543 | |||
1544 | /** |
||
1545 | * Set the current reading mode. |
||
1546 | * |
||
1547 | * @param string $mode |
||
1548 | */ |
||
1549 | public static function set_reading_mode($mode) { |
||
1552 | |||
1553 | /** |
||
1554 | * Get the current reading mode. |
||
1555 | * |
||
1556 | * @return string |
||
1557 | */ |
||
1558 | public static function get_reading_mode() { |
||
1561 | |||
1562 | /** |
||
1563 | * Get the name of the 'live' stage. |
||
1564 | * |
||
1565 | * @return string |
||
1566 | */ |
||
1567 | public static function get_live_stage() { |
||
1570 | |||
1571 | /** |
||
1572 | * Get the current reading stage. |
||
1573 | * |
||
1574 | * @return string |
||
1575 | */ |
||
1576 | public static function current_stage() { |
||
1583 | |||
1584 | /** |
||
1585 | * Get the current archive date. |
||
1586 | * |
||
1587 | * @return string |
||
1588 | */ |
||
1589 | public static function current_archived_date() { |
||
1593 | |||
1594 | /** |
||
1595 | * Set the reading stage. |
||
1596 | * |
||
1597 | * @param string $stage New reading stage. |
||
1598 | */ |
||
1599 | public static function reading_stage($stage) { |
||
1602 | |||
1603 | /** |
||
1604 | * Set the reading archive date. |
||
1605 | * |
||
1606 | * @param string $date New reading archived date. |
||
1607 | */ |
||
1608 | public static function reading_archived_date($date) { |
||
1611 | |||
1612 | |||
1613 | /** |
||
1614 | * Get a singleton instance of a class in the given stage. |
||
1615 | * |
||
1616 | * @param string $class The name of the class. |
||
1617 | * @param string $stage The name of the stage. |
||
1618 | * @param string $filter A filter to be inserted into the WHERE clause. |
||
1619 | * @param boolean $cache Use caching. |
||
1620 | * @param string $sort A sort expression to be inserted into the ORDER BY clause. |
||
1621 | * |
||
1622 | * @return DataObject |
||
1623 | */ |
||
1624 | public static function get_one_by_stage($class, $stage, $filter = '', $cache = true, $sort = '') { |
||
1630 | |||
1631 | /** |
||
1632 | * Gets the current version number of a specific record. |
||
1633 | * |
||
1634 | * @param string $class |
||
1635 | * @param string $stage |
||
1636 | * @param int $id |
||
1637 | * @param boolean $cache |
||
1638 | * |
||
1639 | * @return int |
||
1640 | */ |
||
1641 | public static function get_versionnumber_by_stage($class, $stage, $id, $cache = true) { |
||
1671 | |||
1672 | /** |
||
1673 | * Pre-populate the cache for Versioned::get_versionnumber_by_stage() for |
||
1674 | * a list of record IDs, for more efficient database querying. If $idList |
||
1675 | * is null, then every record will be pre-cached. |
||
1676 | * |
||
1677 | * @param string $class |
||
1678 | * @param string $stage |
||
1679 | * @param array $idList |
||
1680 | */ |
||
1681 | public static function prepopulate_versionnumber_cache($class, $stage, $idList = null) { |
||
1708 | |||
1709 | /** |
||
1710 | * Get a set of class instances by the given stage. |
||
1711 | * |
||
1712 | * @param string $class The name of the class. |
||
1713 | * @param string $stage The name of the stage. |
||
1714 | * @param string $filter A filter to be inserted into the WHERE clause. |
||
1715 | * @param string $sort A sort expression to be inserted into the ORDER BY clause. |
||
1716 | * @param string $join Deprecated, use leftJoin($table, $joinClause) instead |
||
1717 | * @param int $limit A limit on the number of records returned from the database. |
||
1718 | * @param string $containerClass The container class for the result set (default is DataList) |
||
1719 | * |
||
1720 | * @return DataList A modified DataList designated to the specified stage |
||
1721 | */ |
||
1722 | public static function get_by_stage( |
||
1731 | |||
1732 | /** |
||
1733 | * Delete this record from the given stage |
||
1734 | * |
||
1735 | * @param string $stage |
||
1736 | */ |
||
1737 | public function deleteFromStage($stage) { |
||
1748 | |||
1749 | /** |
||
1750 | * Write the given record to the draft stage |
||
1751 | * |
||
1752 | * @param string $stage |
||
1753 | * @param boolean $forceInsert |
||
1754 | * @return int The ID of the record |
||
1755 | */ |
||
1756 | public function writeToStage($stage, $forceInsert = false) { |
||
1766 | |||
1767 | /** |
||
1768 | * Roll the draft version of this record to match the published record. |
||
1769 | * Caution: Doesn't overwrite the object properties with the rolled back version. |
||
1770 | * |
||
1771 | * @param int $version Either the string 'Live' or a version number |
||
1772 | */ |
||
1773 | public function doRollbackTo($version) { |
||
1780 | |||
1781 | /** |
||
1782 | * Return the latest version of the given record. |
||
1783 | * |
||
1784 | * @param string $class |
||
1785 | * @param int $id |
||
1786 | * @return DataObject |
||
1787 | */ |
||
1788 | public static function get_latest_version($class, $id) { |
||
1796 | |||
1797 | /** |
||
1798 | * Returns whether the current record is the latest one. |
||
1799 | * |
||
1800 | * @todo Performance - could do this directly via SQL. |
||
1801 | * |
||
1802 | * @see get_latest_version() |
||
1803 | * @see latestPublished |
||
1804 | * |
||
1805 | * @return boolean |
||
1806 | */ |
||
1807 | public function isLatestVersion() { |
||
1815 | |||
1816 | /** |
||
1817 | * Check if this record exists on live |
||
1818 | * |
||
1819 | * @return bool |
||
1820 | */ |
||
1821 | public function isPublished() { |
||
1833 | |||
1834 | /** |
||
1835 | * Check if this record exists on the draft stage |
||
1836 | * |
||
1837 | * @return bool |
||
1838 | */ |
||
1839 | public function isOnDraft() { |
||
1851 | |||
1852 | |||
1853 | |||
1854 | /** |
||
1855 | * Return the equivalent of a DataList::create() call, querying the latest |
||
1856 | * version of each record stored in the (class)_versions tables. |
||
1857 | * |
||
1858 | * In particular, this will query deleted records as well as active ones. |
||
1859 | * |
||
1860 | * @param string $class |
||
1861 | * @param string $filter |
||
1862 | * @param string $sort |
||
1863 | * @return DataList |
||
1864 | */ |
||
1865 | public static function get_including_deleted($class, $filter = "", $sort = "") { |
||
1873 | |||
1874 | /** |
||
1875 | * Return the specific version of the given id. |
||
1876 | * |
||
1877 | * Caution: The record is retrieved as a DataObject, but saving back |
||
1878 | * modifications via write() will create a new version, rather than |
||
1879 | * modifying the existing one. |
||
1880 | * |
||
1881 | * @param string $class |
||
1882 | * @param int $id |
||
1883 | * @param int $version |
||
1884 | * |
||
1885 | * @return DataObject |
||
1886 | */ |
||
1887 | public static function get_version($class, $id, $version) { |
||
1898 | |||
1899 | /** |
||
1900 | * Return a list of all versions for a given id. |
||
1901 | * |
||
1902 | * @param string $class |
||
1903 | * @param int $id |
||
1904 | * |
||
1905 | * @return DataList |
||
1906 | */ |
||
1907 | public static function get_all_versions($class, $id) { |
||
1914 | |||
1915 | /** |
||
1916 | * @param array $labels |
||
1917 | */ |
||
1918 | public function updateFieldLabels(&$labels) { |
||
1921 | |||
1922 | /** |
||
1923 | * @param FieldList |
||
1924 | */ |
||
1925 | public function updateCMSFields(FieldList $fields) { |
||
1930 | |||
1931 | /** |
||
1932 | * Ensure version ID is reset to 0 on duplicate |
||
1933 | * |
||
1934 | * @param DataObject $source Record this was duplicated from |
||
1935 | * @param bool $doWrite |
||
1936 | */ |
||
1937 | public function onBeforeDuplicate($source, $doWrite) { |
||
1940 | |||
1941 | public function flushCache() { |
||
1944 | |||
1945 | /** |
||
1946 | * Return a piece of text to keep DataObject cache keys appropriately specific. |
||
1947 | * |
||
1948 | * @return string |
||
1949 | */ |
||
1950 | public function cacheKeyComponent() { |
||
1953 | |||
1954 | /** |
||
1955 | * Returns an array of possible stages. |
||
1956 | * |
||
1957 | * @return array |
||
1958 | */ |
||
1959 | public function getVersionedStages() { |
||
1962 | |||
1963 | /** |
||
1964 | * @return string |
||
1965 | */ |
||
1966 | public function getDefaultStage() { |
||
1969 | |||
1970 | public static function get_template_global_variables() { |
||
1975 | } |
||
1976 | |||
2095 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.