Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
E
expire
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
drupal.org
expire
Commits
a62315f1
Commit
a62315f1
authored
Feb 08, 2011
by
Mike Carper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1054580: Add in rules support for expire.
parent
06475fbe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
5 deletions
+126
-5
expire.module
expire.module
+13
-5
expire.rules.inc
expire.rules.inc
+113
-0
No files found.
expire.module
View file @
a62315f1
...
...
@@ -117,7 +117,7 @@ function expire_user($op, &$edit, &$account, $category = NULL) {
// Expire the relevant user page from the static page cache to prevent serving stale content.
if
(
in_array
(
$op
,
$cases
))
{
$paths
[]
=
'user/'
.
$account
->
uid
;
$flushed
=
expire_cache_derivative
(
$
account
,
$paths
,
TRUE
,
TRUE
);
$flushed
=
expire_cache_derivative
(
$
paths
,
$account
);
watchdog
(
'expire'
,
'User !uid was deleted resulting in !flushed pages being expired from the cache'
,
array
(
'!uid'
=>
$account
->
uid
,
'!flushed'
=>
$flushed
,
...
...
@@ -287,7 +287,7 @@ function expire_node(&$node) {
// Flush array of paths
if
(
!
empty
(
$paths
))
{
$flushed
=
expire_cache_derivative
(
$
node
,
$paths
);
$flushed
=
expire_cache_derivative
(
$
paths
,
$node
);
watchdog
(
'expire'
,
'Node !nid was flushed resulting in !flushed pages being expired from the cache'
,
array
(
'!nid'
=>
$node
->
nid
,
'!flushed'
=>
$flushed
,
...
...
@@ -395,12 +395,12 @@ function expire_taxonomy_node_get_tids($nid) {
/**
* Finds all possible paths/redirects/aliases given the root path.
*
* @param $node
* node object
* @param $paths
* Array of current URLs
* @param $node
* node object
*/
function
expire_cache_derivative
(
&
$node
,
$paths
)
{
function
expire_cache_derivative
(
$paths
,
&
$node
=
NULL
)
{
global
$base_path
;
$expire
=
array
();
...
...
@@ -595,3 +595,11 @@ function expire_get_domains(&$node) {
return
$domains
;
}
function
expire_normal_path_check
(
$path
)
{
$original_map
=
arg
(
NULL
,
$path
);
$parts
=
array_slice
(
$original_map
,
0
,
MENU_MAX_PARTS
);
list
(
$ancestors
,
$placeholders
)
=
menu_get_ancestors
(
$parts
);
$router_item
=
db_fetch_array
(
db_query_range
(
'SELECT path FROM {menu_router} WHERE path IN ('
.
implode
(
','
,
$placeholders
)
.
') ORDER BY fit DESC'
,
$ancestors
,
0
,
1
));
return
$router_item
;
}
expire.rules.inc
0 → 100644
View file @
a62315f1
<?php
// $Id$
/**
* @file
* Integration with the rules module
*/
/**
* Implementation of hook_rules_action_info().
*
* @ingroup rules
*/
function
expire_rules_action_info
()
{
return
array
(
'expire_rules_action_flush_url'
=>
array
(
'label'
=>
t
(
'Clear URL(s) from the page cache.'
),
'arguments'
=>
array
(
'urls'
=>
array
(
'type'
=>
'string'
,
'label'
=>
t
(
'URL of page to clear'
)),
),
'module'
=>
'Expire'
,
),
);
}
/**
* Expire a URL from the page cache.
*/
function
expire_rules_action_flush_url
(
$urls
,
$settings
)
{
global
$base_root
,
$base_path
;
$urls
=
preg_replace
(
"/
\r\n
/"
,
"
\n
"
,
$urls
);
$urls
=
explode
(
"
\n
"
,
$urls
);
$urls
=
array_map
(
'trim'
,
$urls
);
$urls
=
array_filter
(
$urls
);
$urls_parsed
=
array_map
(
'parse_url'
,
$urls
);
// Figure out what kind of URL's these are and act accordingly.
$full_urls
=
array
();
$bad_paths
=
array
();
$internal
=
array
();
foreach
(
$urls_parsed
as
$key
=>
$parts
)
{
if
(
!
empty
(
$parts
[
'host'
]))
{
$full_urls
[]
=
$urls
[
$key
];
}
elseif
(
!
empty
(
$parts
[
'path'
]))
{
// Strip base path from path.
$parts
[
'path'
]
=
preg_replace
(
'/^'
.
preg_quote
(
$base_path
,
'/'
)
.
'/i'
,
''
,
$parts
[
'path'
]);
if
(
empty
(
$parts
[
'path'
])
||
$parts
[
'path'
]
==
'<front>'
)
{
$internal
[
$key
]
=
variable_get
(
'site_frontpage'
,
'node'
);
}
else
{
$normal
=
expire_normal_path_check
(
$parts
[
'path'
]);
if
(
is_array
(
$normal
))
{
$internal
[
$key
]
=
$urls
[
$key
];
}
else
{
$normal
=
drupal_get_normal_path
(
$parts
[
'path'
]);
if
(
$normal
==
$parts
[
'path'
])
{
// Bad path given
$bad_paths
[
$key
]
=
$urls
[
$key
];
}
else
{
$internal
[
$key
]
=
$normal
;
}
}
}
}
}
if
(
!
empty
(
$bad_paths
)){
watchdog
(
'expire'
,
'Bad URL(s) given. !url do not match any given paths or aliases'
,
array
(
'!url'
=>
expire_print_r
(
$bad_paths
)));
}
// Process internal paths
foreach
(
$internal
as
$key
=>
$path
)
{
$arg
=
arg
(
NULL
,
$path
);
if
(
$arg
[
0
]
==
'node'
&&
!
empty
(
$arg
[
1
])
&&
is_numeric
(
$arg
[
1
]))
{
$node
=
node_load
(
$arg
[
1
]);
expire_node
(
$node
);
unset
(
$internal
[
$key
]);
}
}
if
(
!
empty
(
$internal
))
{
$flushed
=
expire_cache_derivative
(
$internal
);
}
// Process Full URLs
// hook_expire_cache
$modules
=
module_implements
(
'expire_cache'
);
foreach
(
$modules
as
$module
)
{
module_invoke
(
$module
,
'expire_cache'
,
$full_urls
);
}
watchdog
(
'expire'
,
'Output: !urls <br /> Modules Using hook_expire_cache(): !modules'
,
array
(
'!urls'
=>
expire_print_r
(
$full_urls
),
'!modules'
=>
expire_print_r
(
$modules
),
));
}
/**
* Action clear page from cache configuration form.
*/
function
expire_rules_action_flush_url_form
(
$settings
,
&
$form
)
{
$settings
+=
array
(
'urls'
=>
''
);
$form
[
'settings'
][
'urls'
]
=
array
(
'#type'
=>
'textarea'
,
'#title'
=>
t
(
'URL(s)'
),
'#default_value'
=>
$settings
[
'urls'
],
'#description'
=>
t
(
'Full URL (including http://); node/8; taxonomy/term/3; user/5; path alias; & <front> will work. One Per line.'
),
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment