getResources, get the latest resource per container - modx-revolution

Using getResources, i want to get the latest resource created per container, so here's the resource tree structure:
-Parent
--Container 1
---Resource 1
---Resource 2
---Latest Resource
--Container 2
---Resource 1
---Latest Resource
--Container 3
---Resource 1
---Resource 2
---Latest Resource
By using [[getResources]] how can i possibly be able to get only the resources Latest Resource?

&parents=`1`&sortBy=`publishedOn`&sortdir=`DESC`&limit=`1`
&parents=`2`&sortBy=`publishedOn`&sortdir=`DESC`&limit=`1`
&parents=`3`&sortBy=`publishedOn`&sortdir=`DESC`&limit=`1`
You could also do a getPage with a custom Snippet grabbing the last modResource of the desired parents.
The parents=... above will have to represent actual modResource IDs available in the Manager.

You can do a nested getResources-call.
Assuming that all Containters have the same template (e.g. "3"):
getResources
[[getResources?
&limit=`0`
&depth=`1`
&where=`{"template:=":3}`
&includeContent=`0`
&includeTVs=`0`
&processTVs=`0`
&tpl=`chunk1`
]]
chunk1
[[getResources?
&parents=`[[+id]]`
&sortby=`{"publishedon":"DESC"}`
&hideContainers=`1`
&limit=`1`
&depth=`1`
&includeContent=`1`
&includeTVs=`1`
&processTVs=`1`
&tpl=`chunk2`
]]
chunk2
Here you put the placeholdes you want, e.g. [[+pagetitle]], [[+content]]

Related

How to make a keybind work unconditionally in mpv?

The keys 9 and 0 are, by default, volume- and volume+, respectively.
I often use this stats screen to check filenames and such:
Unfortunately, if I try to increase the volume too quickly after checking the filename, 0 instead changes the stats page to an unhelpful "Internal performance info" screen that looks like this until quitting mpv:
How can I remove this behaviour from the 0 key and make it always act as volume+ instead?
By re- or unbinding all offending (also script-specific) key binds.
While the stats script is active, its key bindings override any existing ones, but those can be changed or removed.
You can add the option key_page_0=key to script-opts/stats.conf in an mpv configuration location such as the following file:
# ~/.config/mpv/script-opts/stats.conf
key_page_0=5
# to disable instead: key_page_0=
Unlike most configuration, this file is NOT cumulative with itself across locations. (everything from /etc/mpv/script-opts/stats.conf is ignored instead of added to if you also have ~/.config/mpv/script-opts/stats.conf)
Or append stats-key_page_0=key to the script-opts list,
such as, to unbind:
mpv --script-opts-append=stats-key_page_0=
or in an mpv.conf file:
# ~/.config/mpv/mpv.conf
script-opts-append=stats-key_page_0=
# to change instead: script-opts-append=stats-key_page_0=5
In the meantime:
You can revert the page back to "Show usual stats" by pressing 1 while shown instead of restarting mpv.
From the mpv manual:
While the stats are visible on screen the following key bindings are
active, regardless of existing bindings. They allow you to switch
between pages of stats:
1 Show usual stats
2 Show frame timings (scroll)
3 Input cache stats
4 Active key bindings (scroll)
0 Internal stuff (scroll)

Docker Wikibase Import Issue

So I installed a Docker Wikibase instance and imported a dump from a WAMP64 Wikibase instance. It imported correctly and everything seems to work, except I can't create new items or properties anymore and I always get a "Could not create a new page. It already exists." error.
Any ideas on how to diagnose or fix? I'm thinking the it's trying to create an item "Q1" where a "Q1" already exists maybe? Any help would be much appreciated!
I figured it out!
Thanks to step 4 here (https://wikibase.consulting/transferring-wikibase-data-between-wikis/), I found out I was right and that Wikibase was trying to create a Q1 where a Q1 already existed. Therefore, I just needed to move the counter to the appropriate number.
Luckily, the above link has access to a script which will do this quick and easy. You can download the link into the root directory of the Wikibase instance using:
curl https://gist.githubusercontent.com/JeroenDeDauw/c86a5ab7e2771301eb506b246f1af7a6/raw/rebuildWikibaseIdCounters.sql -o rebuildWikibaseIdCounters.sql
And execute it with:
php maintenance/sql.php rebuildWikibaseIdCounters.sql
Super fast and painless!
(The raw script is also available here if curl isn't an option for some reason: https://gist.githubusercontent.com/JeroenDeDauw/c86a5ab7e2771301eb506b246f1af7a6/raw/88cdccb1adcdf420d17a3a21296a99f153b95a21/rebuildWikibaseIdCounters.sql)
This is what the script looks like in full:
-- By Jeroen De Dauw / https://Professional.Wiki
-- License: GPL-2.0-or-later
SELECT * FROM /*_*/wb_id_counters;
REPLACE INTO /*_*/wb_id_counters VALUE((SELECT COALESCE(MAX(CAST(SUBSTRING(`page_title`, 2) AS UNSIGNED)), 0) FROM `page` WHERE `page_namespace` = 120), 'wikibase-item');
REPLACE INTO /*_*/wb_id_counters VALUE((SELECT COALESCE(MAX(CAST(SUBSTRING(`page_title`, 2) AS UNSIGNED)), 0) FROM `page` WHERE `page_namespace` = 122), 'wikibase-property');
SELECT * FROM /*_*/wb_id_counters;

How to find the file paths of all namespace loaded in an application using tcl/TK under Unix?

For existing flow, there would be a whole bunch of namespaces loaded when running some script job.
However, if I want to check & trace the usage of some command in some namespace, I need to find the script path of the certain namespace.
Is there some way to get that? Particularly, I'm talking about Primetime scripts.
Technically, namespaces don't have script paths. But we can do something close enough:
proc report_current_file {call code result op} {
if {$code == 0} {
# If the [proc] call was successful...
set cmd [lindex $call 1]
set qualified_cmd [uplevel 1 [list namespace which $cmd]]
set file [file normalize [info script]]
puts "Defined $qualified_cmd in $file"
}
}
trace add execution proc leave report_current_file
It's not perfect if you've got procedures creating procedures dynamically — the current file might be wrong — but that's fortunately not what most code does.
Another option that might work for you is to use tcl::unsupported::getbytecode, which produces a lot of information in machine-readable format (a dictionary). One of the pieces of information is the sourcefile key. Here's an example running interactively on my machine:
% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(engine) = Tcl
tcl_platform(machine) = x86_64
tcl_platform(os) = Darwin
tcl_platform(osVersion) = 20.2.0
tcl_platform(pathSeparator) = :
tcl_platform(platform) = unix
tcl_platform(pointerSize) = 8
tcl_platform(threaded) = 1
tcl_platform(user) = dkf
tcl_platform(wordSize) = 8
% dict get [tcl::unsupported::getbytecode proc parray] sourcefile
/opt/local/lib/tcl8.6/parray.tcl
Note that the procedure has to be already defined for this to work. And if Tcl's become confused about what file the code was in (because of dynamic programming trickery) then that key is absent.

Asterisk. Get number of active calls in dialplan

I have production asterisk 16.4 with dialplan on LUA and two SIP providers. The first provider give me trunk with maximum 5 connections and the second provider give trunck with 20 connections. I prefer to use the first provider for outgoing calls because it is cheaper, but it have only 5 lines. So, when user makes an outgoing call, I want to check current number of active calls on the trunk of first provider, and if that number is 5 then route the call throught second provider.
The question is - How can I get in dialplan number of active calls? Is there some functions or core variables? I know that I can get list of active channels in CLI by command "core show channels verbose", but how can I get somthing like this in lua dialplan?
Thanks to #arheops for the clue. This is a working example on lua.
ext = extension:sub(1); -- Remove leading 9
local providerA = tonumber(channel['GROUP_COUNT(provA)']:get());
app.Verbose("Active channels on provider A = "..providerA);
if providerA < 5 then
channel['GROUP()']:set("provA");
app.Verbose("Outgoing call throught Provider A "..ext);
app.Dial("PJSIP/"..ext.."#trunc_providerA");
else
app.Verbose("Outgoing call throught Provider B "..ext);
app.Dial("PJSIP/"..ext.."#trunc_providerB");
end;
app.Hangup();
You can set GROUP for each channel and after that cont GROUP_COUNT in dialplan
https://www.voip-info.org/asterisk-func-group/

bitbucket API 2.0 page parameters using non-default pagelen

I have run into a cumbersome limitation of the bitbucket API 2.0 - I am hoping there is a way to make it more usable.
When one wants to retrieve a list of repositories from the bitbucket API 2.0, this url can be used:
https://api.bitbucket.org/2.0/repositories/{teamname}
This returns the first 10 repos in the list. To access the next 10, one simply needs to add a page parameter:
https://api.bitbucket.org/2.0/repositories/{teamname}?page=2
This returns the next 10. One can also adjust the number of results returned using the pagelen parameter, like so:
https://api.bitbucket.org/2.0/repositories/{teamname}?pagelen=100
The maximum number can vary per account, but 100 is the maximum any team is able to request with each API call. The cumbersome part is that I cannot find a way to get page 2 with a pagelen of 100. I have tried variations on the following:
https://api.bitbucket.org/2.0/repositories/{teamname}?pagelen=100&page=2
https://api.bitbucket.org/2.0/repositories/{teamname}?page=2&pagelen=100
I've also tried using parameters such as limit or size to no avail. Is the behavior I seek even possible? Some relevant documentation can be found here.
EDIT: It appears this behavior is possible, however the bitbucket 2.0 API will only recognize multiple parameters if the entire url is in quotes.
Example:
curl "https://api.bitbucket.org/2.0/repositories/{teamname}?pagelen=100&page=2"
ORIGINAL ANSWER: I was able to get around this by creating a bash script that looped through each page of 10 results, adding each new 10 repos to a temporary file and then cloning into those 10 repos. The only manual thing that needs to be done is to update the upper limit in the for loop to be the last page expected.
Here is an example script:
for thisPage in {1..23}
do
curl https://api.bitbucket.org/2.0/repositories/[organization]?page=$thisPage -u [username]:[password] > repoinfo
for repo_name in `cat repoinfo | sed -r 's/("slug": )/\n\1/g' | sed -r 's/"slug": "(.*)"/\1/' | sed -e 's/{//' | cut -f1 -d\" | tr '\n' ' '`
do
echo "Cloning " $repo_name
git clone https://[username]#bitbucket.org/[organization]/$repo_name
echo "---"
done
done
Much help was gleaned from:
https://haroldsoh.com/2011/10/07/clone-all-repos-from-a-bitbucket-source/
and http://adomingues.github.io/2015/01/10/clone-all-repositories-from-a-user-bitbucket/ Thanks!

Resources