public
Description: Midgard Components Framework 3rd generation
Homepage: http://www.midgard-project.org
Clone URL: git://github.com/bergie/midcom.git
Working locking and unlocking if controller implements the necessary 
methods
bergie (author)
Fri Jun 27 11:04:10 -0700 2008
commit  dc27dd982441a18b8ba5004131f298bbb4cb6a52
tree    d1866503c42a1b44d445ef5642ef26346035ffc3
parent  f9be98365a9e911734570eab0ddabdd5cd06f962
...
50
51
52
 
 
 
 
 
 
53
54
55
...
50
51
52
53
54
55
56
57
58
59
60
61
0
@@ -50,6 +50,12 @@ class midcom_core_controllers_page extends midcom_core_controllers_baseclasses_m
0
     {
0
     }
0
 
0
+ public function get_object_show($route_id, &$data, $args)
0
+ {
0
+ $this->load_object($args);
0
+ return $this->object;
0
+ }
0
+
0
     public function action_show($route_id, &$data, $args)
0
     {
0
         parent::action_show($route_id, &$data, $args);
...
25
26
27
28
 
 
 
 
 
 
 
 
 
 
29
30
31
...
121
122
123
 
 
 
 
 
 
 
 
 
 
 
 
 
124
125
126
...
259
260
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
263
264
...
25
26
27
 
28
29
30
31
32
33
34
35
36
37
38
39
40
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
0
@@ -25,7 +25,16 @@ class midcom_core_controllers_snippets
0
     private function get_snippetdir_children($snippetdir_id)
0
     {
0
         // Load children for PROPFIND purposes
0
- $children = array();
0
+ $children = array
0
+ (
0
+ array
0
+ (
0
+ 'uri' => "{$_MIDCOM->context->prefix}__snippets{$this->object_path}/", // FIXME: dispatcher::generate_url
0
+ 'title' => $this->object_path,
0
+ 'mimetype' => 'httpd/unix-directory',
0
+ 'resource' => 'collection',
0
+ )
0
+ );
0
         
0
         // Snippetdirs
0
         $mc = midgard_snippetdir::new_collector('up', $snippetdir_id);
0
@@ -121,6 +130,19 @@ class midcom_core_controllers_snippets
0
             {
0
                 throw new midcom_exception_notfound("Snippetdir {$this->object_path} not found");
0
             }
0
+
0
+ // Just put the snippet itself there
0
+ $data['children'] = array
0
+ (
0
+ array
0
+ (
0
+ 'uri' => "{$_MIDCOM->context->prefix}__snippets{$this->object_path}", // FIXME: dispatcher::generate_url
0
+ 'title' => $this->snippet->name,
0
+ 'mimetype' => 'text/plain',
0
+ 'size' => $this->snippet->metadata->size,
0
+ 'revised' => $this->snippet->metadata->revised,
0
+ )
0
+ );
0
             return;
0
         }
0
         
0
@@ -259,6 +281,27 @@ class midcom_core_controllers_snippets
0
         $this->snippetdir->update();
0
     }
0
     
0
+ public function get_object_webdav($route_id, &$data, $args)
0
+ {
0
+ if ($route_id == 'snippets_root')
0
+ {
0
+ return null;
0
+ }
0
+
0
+ $object_path = '/' . implode('/', $args['variable_arguments']);
0
+ //echo "{$object_path}\n";
0
+ if ($this->get_snippetdir($object_path))
0
+ {
0
+ return $this->snippetdir;
0
+ }
0
+ if ($this->get_snippet($object_path))
0
+ {
0
+ return $this->snippet;
0
+ }
0
+
0
+ return null;
0
+ }
0
+
0
     public function action_webdav($route_id, &$data, $args)
0
     {
0
         if ($route_id == 'snippets')
...
93
94
95
 
 
 
 
 
96
97
98
...
135
136
137
 
 
 
 
138
139
140
...
93
94
95
96
97
98
99
100
101
102
103
...
140
141
142
143
144
145
146
147
148
149
0
@@ -93,6 +93,11 @@ class midcom_core_helpers_metadata
0
     public static function lock(&$object, $shared = false, $token = null)
0
     {
0
         $_MIDCOM->authorization->require_do('midgard:update', $object);
0
+
0
+ // Re-fetch the object to be safe
0
+ $class = get_class($object);
0
+ $object = new $class($object->guid);
0
+
0
         $object->metadata->locked = gmstrftime('%Y-%m-%d %T', time());
0
 
0
         if ($shared)
0
@@ -135,6 +140,10 @@ class midcom_core_helpers_metadata
0
     {
0
         $_MIDCOM->authorization->require_do('midgard:update', $object);
0
         
0
+ // Re-fetch the object to be safe
0
+ $class = get_class($object);
0
+ $object = new $class($object->guid);
0
+
0
         $allowed = false;
0
         if ($_MIDCOM->authentication->is_user())
0
         {
...
251
252
253
254
 
255
256
257
...
251
252
253
 
254
255
256
257
0
@@ -251,7 +251,7 @@ class midcom_core_helpers_resolver
0
         
0
         return array('route' => $selected_route_configuration,
0
                      'route_id' => $this->route_id,
0
- 'actions_arguments' => array(),
0
+ 'action_arguments' => $this->action_arguments,
0
                      'page' => new midgard_page($this->page_id));
0
 
0
         // Handle allowed HTTP methods
...
105
106
107
108
 
109
110
111
...
121
122
123
 
 
 
 
 
124
125
126
...
348
349
350
351
352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
354
355
356
357
358
359
 
360
361
362
363
364
 
365
366
367
368
369
370
371
 
372
373
374
375
376
377
...
382
383
384
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
386
387
...
393
394
395
 
396
397
398
...
420
421
422
423
 
424
425
426
427
428
429
430
431
 
 
432
433
434
...
441
442
443
444
 
445
446
447
...
105
106
107
 
108
109
110
111
...
121
122
123
124
125
126
127
128
129
130
131
...
353
354
355
 
 
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
 
379
380
381
382
383
 
384
385
386
387
388
389
 
 
390
391
392
 
393
394
395
...
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
...
436
437
438
439
440
441
442
...
464
465
466
 
467
468
469
470
471
472
473
 
 
474
475
476
477
478
...
485
486
487
 
488
489
490
491
0
@@ -105,7 +105,7 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
     function PROPFIND(&$options, &$files)
0
     {
0
         $this->filename_check();
0
-
0
+
0
         $_MIDCOM->authorization->require_user();
0
 
0
         // Run the controller
0
@@ -121,6 +121,11 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
             $data['children'] = $this->get_node_children($page);
0
         }
0
         
0
+ if (empty($data['children']))
0
+ {
0
+ return false;
0
+ }
0
+
0
         // Convert children to PROPFIND elements
0
         $this->children_to_files($data['children'], &$files);
0
         
0
@@ -348,30 +353,43 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
     function LOCK(&$options)
0
     {
0
         $options['timeout'] = time() + $_MIDCOM->configuration->get('metadata_lock_timeout');
0
- return "200 OK";
0
- /*
0
+
0
+ // Run the controller
0
+ $controller = $this->controller;
0
+ $action_method = str_replace('action_', 'get_object_', $this->action_method);
0
+
0
+ if (!method_exists($controller, $action_method))
0
+ {
0
+ throw new midcom_exception_httperror("Locking not allowed", 405);
0
+ }
0
+
0
+ $data =& $options;
0
+ $object = $controller->$action_method($this->route_id, $data, $this->action_arguments);
0
+ if (!$object)
0
+ {
0
+ throw new midcom_exception_notfound("No lockable objects");
0
+ }
0
+
0
         $shared = false;
0
         if ($options['scope'] == 'shared')
0
         {
0
             $shared = true;
0
         }
0
         
0
- if (is_null($info['object']))
0
+ if (is_null($object))
0
         {
0
             throw new midcom_exception_notfound("Not found");
0
         }
0
         
0
- if (midcom_core_helpers_metadata::is_locked($info['object']))
0
+ if (midcom_core_helpers_metadata::is_locked($object))
0
         {
0
             $this->logger->log("Object is locked by another user");
0
             return "423 Locked";
0
         }
0
 
0
- midcom_core_helpers_metadata::lock($info['object'], $shared, $options['locktoken']);
0
- $options['timeout'] = time() + $_MIDCOM->configuration->get('metadata_lock_timeout');
0
+ midcom_core_helpers_metadata::lock($object, $shared, $options['locktoken']);
0
         
0
         return "200 OK";
0
- */
0
     }
0
     
0
     /**
0
@@ -382,6 +400,31 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
      */
0
     function UNLOCK(&$options)
0
     {
0
+ // Run the controller
0
+ $controller = $this->controller;
0
+ $action_method = str_replace('action_', 'get_object_', $this->action_method);
0
+
0
+ if (!method_exists($controller, $action_method))
0
+ {
0
+ throw new midcom_exception_httperror("Locking not allowed", 405);
0
+ }
0
+
0
+ $data =& $options;
0
+ $object = $controller->$action_method($this->route_id, $data, $this->action_arguments);
0
+ if (!$object)
0
+ {
0
+ throw new midcom_exception_notfound("No lockable objects");
0
+ }
0
+
0
+ if (midcom_core_helpers_metadata::is_locked($object ))
0
+ {
0
+ $this->logger->log("Object is locked by another user {$object->metadata->locker}");
0
+ return "423 Locked";
0
+ }
0
+
0
+ $this->logger->log("Unlocking");
0
+ midcom_core_helpers_metadata::unlock($object);
0
+
0
         return "200 OK";
0
     }
0
 
0
@@ -393,6 +436,7 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
      */
0
     function checkLock($path)
0
     {
0
+ $this->logger->log("CHECKLOCK: {$path}");
0
         if (isset($this->locks[$path]))
0
         {
0
             return $this->locks[$path];
0
@@ -420,15 +464,15 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
             $this->logger->log('Resolver got "' . $e->getMessage() . '"');
0
         }
0
 
0
- if (!in_array('PROPFIND', $resolution['controller']['allowed_methods']))
0
+ if (!in_array('PROPFIND', $resolution['route']['allowed_methods']))
0
         {
0
             // No PROPFIND supported, so don't supply lock information either
0
             $this->locks[$path] = false;
0
             return $this->locks[$path];
0
         }
0
 
0
- $controller_class = $resolution['controller']['controller'];
0
- $action_method = "get_object_{$resolution['controller']['action']}";
0
+ $controller_class = $resolution['route']['controller'];
0
+ $action_method = "get_object_{$resolution['route']['action']}";
0
 
0
         if (!method_exists($controller_class, $action_method))
0
         {
0
@@ -441,7 +485,7 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
         $controller->dispatcher = $_MIDCOM->dispatcher;
0
 
0
         $data = array();
0
- $object = $controller->$action_method($resolution['controller']['route_id'], $data, $resolution['controller']['route_id']);
0
+ $object = $controller->$action_method($resolution['route_id'], $data, $resolution['action_arguments']);
0
 
0
         if (!$object)
0
         {

Comments

    No one has commented yet.