Jump to content


querying a key in a PHP module

swarm PHP module key keys

  • Please log in to reply
3 replies to this topic

#1 PeteS

PeteS

    Advanced Member

  • Members
  • PipPipPip
  • 62 posts

Posted 10 July 2015 - 03:52 PM

When writing a custom Swarm Module.php using the P4 library, how do you fetch the value of a key (e.g. the equivalent of the Perforce command: p4 key slackuser-joe)?

P4/Key/Key looks close, but that appears to be for getting all counters. I merely want to query a specific key.

Are there any docs for the P4 modules? I can't seem to find them.

Thanks!

#2 PeteS

PeteS

    Advanced Member

  • Members
  • PipPipPip
  • 62 posts

Posted 10 July 2015 - 06:14 PM

After a bit of grepping & trial and error, it looks like I found my answer:

use P4\Key\Key;

$p4Admin = $services->get('p4_admin');
$myKey = "theInterestingKey";

if (! Key::exists ($myKey, $p4Admin))
	return "None";

return Key::fetch ($myKey, $p4Admin)->get();

I do have a follow-up question though: is there a way to make the search case insensitive?

#3 PeteS

PeteS

    Advanced Member

  • Members
  • PipPipPip
  • 62 posts

Posted 15 July 2015 - 05:16 AM

For completeness I should add that the great folks in Perforce Support also pointed me to the docs for the Perforce PHP classes: http://www.perforce....hp.classes.html. These would also probably work (although I hadn't tried them).

I believe a key difference between the two is that using P4\Key\Key would be using the Swarm authentication (which would already be active), as opposed to establishing credentials through the P4PHP module.

HTH,
Pete

#4 hoang.nth

hoang.nth

    Member

  • Members
  • PipPip
  • 16 posts

Posted 18 December 2015 - 06:28 AM

Hello Mr Pete,

I have a question  that, could we fetchAll the keys. actually i used these code, but they are not work and i get error 500

$p4Admin = $services->get ( 'p4_admin' );
$infos = Key::fetchAll(array(Key::FETCH_BY_NAME() => 'swarm-review'),$p4Admin);
var_dump($infos);

Please kindly help me to check it.
Thank you so much



Also tagged with one or more of these keywords: swarm, PHP, module, key, keys

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users