Merge branch 'release/0.11' of github.com:tainacan/tainacan into release/0.11
This commit is contained in:
commit
7ac60dab0e
|
@ -400,7 +400,7 @@ class REST_Filters_Controller extends REST_Controller {
|
||||||
*/
|
*/
|
||||||
public function get_items_permissions_check( $request ) {
|
public function get_items_permissions_check( $request ) {
|
||||||
if(!isset($request['collection_id'])) {
|
if(!isset($request['collection_id'])) {
|
||||||
if ( 'edit' === $request['context'] && ! $this->filter_repository->can_read( new Entities\Filter() ) ) {
|
if ( 'edit' === $request['context'] && ! $this->filter_repository->can_edit( new Entities\Filter() ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -378,6 +378,8 @@ class REST_Metadata_Controller extends REST_Controller {
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function get_items_permissions_check( $request ) {
|
public function get_items_permissions_check( $request ) {
|
||||||
|
|
||||||
|
if(!isset($request['collection_id'])) {
|
||||||
if ( 'edit' === $request['context'] && ! $this->metadatum_repository->can_edit( new Entities\Metadatum() ) ) {
|
if ( 'edit' === $request['context'] && ! $this->metadatum_repository->can_edit( new Entities\Metadatum() ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -385,6 +387,19 @@ class REST_Metadata_Controller extends REST_Controller {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$collection = $this->collection_repository->fetch($request['collection_id']);
|
||||||
|
|
||||||
|
if($collection instanceof Entities\Collection){
|
||||||
|
if ( 'edit' === $request['context'] && ! $collection->can_read() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \WP_REST_Request $request
|
* @param \WP_REST_Request $request
|
||||||
*
|
*
|
||||||
|
|
|
@ -12,8 +12,8 @@ class Cli_Garbage_Collector {
|
||||||
*
|
*
|
||||||
* ## OPTIONS
|
* ## OPTIONS
|
||||||
*
|
*
|
||||||
* [--dry-run]
|
* [--run]
|
||||||
* : Look for garbage but do not delete anything, just output a report
|
* : By default, this command only looks for garbage and output a report, but does not delete anything. If you want to really delete the garbage, pass --run
|
||||||
*
|
*
|
||||||
* [--deep]
|
* [--deep]
|
||||||
* : More aressive approach finding garbage. In some cases it could delete something related to other parts of the website. Currently, deep mode deletes all attachments with broken parent IDs, regardless whether they were uploaded via tainacan or not
|
* : More aressive approach finding garbage. In some cases it could delete something related to other parts of the website. Currently, deep mode deletes all attachments with broken parent IDs, regardless whether they were uploaded via tainacan or not
|
||||||
|
@ -30,12 +30,20 @@ class Cli_Garbage_Collector {
|
||||||
* [--skip-metadata]
|
* [--skip-metadata]
|
||||||
* : Do not try to find orphan and unused metadata
|
* : Do not try to find orphan and unused metadata
|
||||||
*
|
*
|
||||||
|
* [--yes]
|
||||||
|
* : Skip confirmation before execution
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function __invoke($args, $assoc_args) {
|
public function __invoke($args, $assoc_args) {
|
||||||
|
|
||||||
$dry_run = isset($assoc_args['dry-run']);
|
$dry_run = ! isset($assoc_args['run']);
|
||||||
$deep = isset($assoc_args['deep']);
|
$deep = isset($assoc_args['deep']);
|
||||||
|
|
||||||
|
if (!$dry_run) {
|
||||||
|
\WP_CLI::warning( 'It is strongly recommended you do a backup before running this command, as there is no way to undo it.' );
|
||||||
|
\WP_CLI::confirm( 'Are you sure you want to look for and DELETE all the garbage? ', $assoc_args );
|
||||||
|
}
|
||||||
|
|
||||||
// delete attachments
|
// delete attachments
|
||||||
if (!isset($assoc_args['skip-attachments'])) {
|
if (!isset($assoc_args['skip-attachments'])) {
|
||||||
$this->delete_attachments($dry_run, $deep);
|
$this->delete_attachments($dry_run, $deep);
|
||||||
|
@ -59,6 +67,10 @@ class Cli_Garbage_Collector {
|
||||||
|
|
||||||
// delete bulk post meta
|
// delete bulk post meta
|
||||||
|
|
||||||
|
if ($dry_run) {
|
||||||
|
\WP_CLI::warning( 'Nothing was done. If you want to delete all the found garbage, run the command with --run option.' );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,11 +280,10 @@ class Cli_Garbage_Collector {
|
||||||
$orphan_metadata = $wpdb->get_col( "SELECT p.ID FROM $wpdb->postmeta pm JOIN $wpdb->posts p ON p.ID = pm.post_id
|
$orphan_metadata = $wpdb->get_col( "SELECT p.ID FROM $wpdb->postmeta pm JOIN $wpdb->posts p ON p.ID = pm.post_id
|
||||||
WHERE p.post_type = 'tainacan-metadatum' AND
|
WHERE p.post_type = 'tainacan-metadatum' AND
|
||||||
pm.meta_key = 'collection_id' AND
|
pm.meta_key = 'collection_id' AND
|
||||||
pm.meta_value NOT IN (SELECT ID FROM $wpdb->posts WHERE post_type = 'tainacan-collection')
|
pm.meta_value NOT IN (SELECT ID FROM $wpdb->posts WHERE post_type = 'tainacan-collection') AND
|
||||||
|
pm.meta_value <> 'default'
|
||||||
" );
|
" );
|
||||||
|
|
||||||
var_dump(count($orphan_metadata));
|
|
||||||
|
|
||||||
$meta_to_delete = array_merge($deleted_metadata, $orphan_metadata);
|
$meta_to_delete = array_merge($deleted_metadata, $orphan_metadata);
|
||||||
|
|
||||||
$meta_to_delete_count = count($meta_to_delete);
|
$meta_to_delete_count = count($meta_to_delete);
|
||||||
|
|
Loading…
Reference in New Issue