Version 5.0.6
This commit is contained in:
1 parent
a3a4a9ccbd
commit
b89858b2ff
1214 files changed
+92828
-14859
No files matched your search
@@ -11,28 +11,28 @@
|
||||
|
||||
namespace IPS\core\modules\admin\discovery;
|
||||
|
||||
use IPS\Content;
|
||||
use InvalidArgumentException;
|
||||
use IPS\Content\Tag;
|
||||
use IPS\Content\Taggable;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\Stack;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\IPS;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Output;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
use function in_array;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
@@ -108,6 +108,27 @@ class tags extends Controller
|
||||
'title' => 'tag_settings'
|
||||
];
|
||||
|
||||
Output::i()->sidebar['actions']['tools'] = [
|
||||
'icon' => 'cog',
|
||||
'title' => 'tag_tools',
|
||||
'menu' => [
|
||||
'merge' => [
|
||||
'icon' => 'level-up',
|
||||
'title' => 'merge_tag_tool',
|
||||
'link' => $this->url->setQueryString( 'do', 'merge' ),
|
||||
'data' => [ 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack( 'merge_tag_tool') ]
|
||||
],
|
||||
'delete' => [
|
||||
'icon' => 'trash',
|
||||
'title' => 'tags_mass_delete',
|
||||
'link' => $this->url->setQueryString( 'do', 'massDelete' ),
|
||||
'data' => [ 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack( 'tags_mass_delete') ]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_core.js', 'core', 'admin' ) );
|
||||
|
||||
parent::manage();
|
||||
}
|
||||
|
||||
@@ -197,4 +218,127 @@ class tags extends Controller
|
||||
Output::i()->breadcrumb[] = [ null, Member::loggedIn()->language()->addToStack( 'tag_settings' ) ];
|
||||
Output::i()->output = (string) $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function merge() : void
|
||||
{
|
||||
/* Skip any tags that are being merged */
|
||||
$source = [];
|
||||
foreach( new ActiveRecordIterator(
|
||||
Db::i()->select( '*', 'core_tags_data', null, 'tag_text' ),
|
||||
Tag::class
|
||||
) as $tag )
|
||||
{
|
||||
if( !$tag->mergeInProgress() )
|
||||
{
|
||||
$source[] = $tag->text;
|
||||
}
|
||||
}
|
||||
|
||||
$form = new Form( 'form', 'continue' );
|
||||
$form->add( new Text( 'tag_merge_from', null, true, [
|
||||
'autocomplete' => array(
|
||||
'unique' => TRUE,
|
||||
'source' => $source,
|
||||
'resultItemTemplate' => 'core.autocomplete.tagsResultItem',
|
||||
'freeChoice' => false,
|
||||
'minimized' => false,
|
||||
'alphabetical' => true,
|
||||
'addTokenText' => Member::loggedIn()->language()->get( 'tags_optional' ),
|
||||
)
|
||||
] ) );
|
||||
|
||||
$form->add( new Text( 'tag_merge_to', null, true, [
|
||||
'autocomplete' => array(
|
||||
'unique' => TRUE,
|
||||
'source' => $source,
|
||||
'resultItemTemplate' => 'core.autocomplete.tagsResultItem',
|
||||
'freeChoice' => false,
|
||||
'minimized' => false,
|
||||
'alphabetical' => true,
|
||||
'maxItems' => 1,
|
||||
'addTokenText' => Member::loggedIn()->language()->get( 'tags_optional' ),
|
||||
)
|
||||
], function( $val ){
|
||||
if( $val )
|
||||
{
|
||||
if( in_array( $val, explode( "\n", Request::i()->tag_merge_from ) ) )
|
||||
{
|
||||
throw new InvalidArgumentException( 'err__bad_tag_merge' );
|
||||
}
|
||||
}
|
||||
} ) );
|
||||
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
foreach( $values['tag_merge_from'] as $tag )
|
||||
{
|
||||
$tag = Tag::load( $tag, 'tag_text' );
|
||||
|
||||
/* Yes, this is technically used for totals, but we're wiping this anyway,
|
||||
so just put a placeholder here */
|
||||
$data = $tag->totals;
|
||||
$data['merge'] = true;
|
||||
$tag->totals = $data;
|
||||
$tag->save();
|
||||
|
||||
/* Queue the background task to update the tags */
|
||||
Task::queue( 'core', 'UpdateTaggedItems', [ 'tag' => $tag->text, 'new' => $values['tag_merge_to'], 'merge' => true ], 5, [ 'tag' ] );
|
||||
}
|
||||
|
||||
Output::i()->redirect( $this->url, Member::loggedIn()->language()->addToStack( 'tag_merge_requested' ) );
|
||||
}
|
||||
|
||||
Output::i()->output = (string) $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk delete tool
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function massDelete() : void
|
||||
{
|
||||
/* Skip any tags that are being merged */
|
||||
$source = [];
|
||||
foreach( new ActiveRecordIterator(
|
||||
Db::i()->select( '*', 'core_tags_data', null, 'tag_text' ),
|
||||
Tag::class
|
||||
) as $tag )
|
||||
{
|
||||
if( !$tag->mergeInProgress() )
|
||||
{
|
||||
$source[] = $tag->text;
|
||||
}
|
||||
}
|
||||
|
||||
$form = new Form( 'form', 'submit' );
|
||||
$form->attributes['data-controller'] = 'core.admin.core.tags';
|
||||
|
||||
$form->add( new Text( 'tag_to_delete', null, true, [
|
||||
'autocomplete' => array(
|
||||
'unique' => TRUE,
|
||||
'source' => $source,
|
||||
'resultItemTemplate' => 'core.autocomplete.tagsResultItem',
|
||||
'freeChoice' => false,
|
||||
'minimized' => false,
|
||||
'alphabetical' => true,
|
||||
'addTokenText' => Member::loggedIn()->language()->get( 'tags_optional' ),
|
||||
)
|
||||
] ) );
|
||||
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
foreach( $values['tag_to_delete'] as $tag )
|
||||
{
|
||||
Tag::load( $tag, 'tag_text' )->delete();
|
||||
}
|
||||
|
||||
Output::i()->redirect( $this->url );
|
||||
}
|
||||
|
||||
Output::i()->output = (string) $form;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user