-
Notifications
You must be signed in to change notification settings - Fork 623
Expand file tree
/
Copy pathxmlrpc.class.php
More file actions
9203 lines (8256 loc) · 351 KB
/
xmlrpc.class.php
File metadata and controls
9203 lines (8256 loc) · 351 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* TestLink Open Source Project http://testlink.sourceforge.net/
* This script is distributed under the GNU General Public License 2 or later.
*
* @filesource xmlrpc.class.php
*
* @author Asiel Brumfield <asielb@users.sourceforge.net>
* @package TestlinkAPI
*
* Testlink API makes it possible to interact with Testlink
* using external applications and services. This makes it possible to report test results
* directly from automation frameworks as well as other features.
*
* See examples for additional detail
* @example sample_clients/java/org/testlink/api/client/sample/TestlinkAPIXMLRPCClient.java java client sample
* @example sample_clients/php/clientSample.php php client sample
* @example sample_clients/ruby/clientSample.rb ruby client sample
* @example sample_clients/python/clientSample.py python client sample
*
*/
/**
* IXR is the class used for the XML-RPC server
*/
define( "TL_APICALL", 'XML-RPC' );
require_once("../../../../config.inc.php");
require_once("common.php");
require_once("xml-rpc/class-IXR.php");
require_once("api.const.inc.php");
require_once("APIErrors.php");
/**
* The entry class for serving XML-RPC Requests
*
* See examples for additional detail
*
* @example sample_clients/java/org/testlink/api/client/sample/TestlinkAPIXMLRPCClient.java java client sample
* @example sample_clients/php/clientSample.php php client sample
* @example sample_clients/ruby/clientSample.rb ruby client sample
* @example sample_clients/python/clientSample.py python client sample
*
* @author Asiel Brumfield <asielb@users.sourceforge.net>
* @package TestlinkAPI
* @since Class available since Release 1.8.0
*/
class TestlinkXMLRPCServer extends IXR_Server {
public static $version = "1.1";
const OFF = false;
const ON = true;
const BUILD_GUESS_DEFAULT_MODE = OFF;
const SET_ERROR = true;
const CHECK_PUBLIC_PRIVATE_ATTR = true;
const THROW_ON_ERROR = true;
/**
* The DB object used throughout the class
*
* @access protected
*/
protected $dbObj = null;
protected $tables = null;
protected $tcaseMgr = null;
protected $tprojectMgr = null;
protected $tplanMgr = null;
protected $tplanMetricsMgr = null;
protected $reqSpecMgr = null;
protected $reqMgr = null;
protected $platformMgr = null;
protected $itsMgr = null;
protected $userMgr = null;
/**
* Whether the server will run in a testing mode
*/
protected $testMode = false;
/**
* userID associated with the devKey provided
*/
protected $userID = null;
/**
* UserObject associated with the userID
*/
protected $user = null;
/**
* array where all the args are stored for requests
*/
protected $args = null;
/**
* array where error codes and messages are stored
*/
protected $errors = array();
/**
* The api key being used to make a request
*/
protected $devKey = null;
/**
* boolean to allow a method to invoke another method and avoid double auth
*/
protected $authenticated = false;
/**
* The version of a test case that is being used
*/
/**
* This value is setted in following method:
*/
/**
* _checkTCIDAndTPIDValid()
*/
protected $tcVersionID = null;
protected $versionNumber = null;
/**
* Mapping bewteen external & internal test case ID
*/
protected $tcaseE2I = null;
/**
* needed in order to manage logs
*/
protected $tlLogger = null;
/**
* #@+
* string for parameter names are all defined statically
* PLEASE define in DICTIONARY ORDER
*
* @static
*/
public static $actionOnDuplicatedNameParamName = "actiononduplicatedname";
public static $actionParamName = "action";
public static $activeParamName = "active";
public static $assignedToParamName = "assignedto";
public static $automatedParamName = "automated";
public static $authorLoginParamName = "authorlogin";
public static $bugIDParamName = "bugid";
public static $buildIDParamName = "buildid";
public static $buildNameParamName = "buildname";
public static $buildNotesParamName = "buildnotes";
public static $checkDuplicatedNameParamName = "checkduplicatedname";
public static $contentParamName = "content";
public static $customFieldNameParamName = "customfieldname";
public static $customFieldsParamName = "customfields";
public static $deepParamName = "deep";
public static $descriptionParamName = "description";
public static $detailsParamName = "details";
public static $devKeyParamName = "devKey";
public static $executionIDParamName = "executionid";
public static $executionOrderParamName = "executionorder";
public static $executedParamName = "executed";
public static $executeStatusParamName = "executestatus";
public static $executionTypeParamName = "executiontype";
public static $expectedResultsParamName = "expectedresults";
public static $fileNameParamName = "filename";
public static $fileTypeParamName = "filetype";
public static $foreignKeyIdParamName = "fkid";
public static $foreignKeyTableNameParamName = "fktable";
public static $guessParamName = "guess";
public static $getStepsInfoParamName = "getstepsinfo";
public static $getKeywordsParamName = "getkeywords";
public static $importanceParamName = "importance";
public static $internalIDParamName = "internalid";
public static $keywordIDParamName = "keywordid";
public static $keywordNameParamName = "keywords";
public static $linkIDParamName = "linkid";
public static $nodeIDParamName = "nodeid";
public static $nodeTypeParamName = "nodetype";
public static $noteParamName = "notes";
public static $openParamName = "open";
public static $optionsParamName = "options";
public static $orderParamName = "order";
public static $overwriteParamName = "overwrite";
public static $parentIDParamName = "parentid";
public static $platformNameParamName = "platformname";
public static $platformIDParamName = "platformid";
public static $platformOnDesignParamName = "platformondesign";
public static $platformOnExecutionParamName = "platformonexecution";
public static $preconditionsParamName = "preconditions";
public static $publicParamName = "public";
public static $releaseDateParamName = "releasedate";
public static $roleIDParamName = "roleid";
public static $roleNameParamName = "rolename";
public static $requirementsParamName = "requirements";
public static $requirementIDParamName = "requirementid";
public static $requirementVersionIDParamName = "requirementversionid";
public static $requirementDocIDParamName = "requirementdocid";
public static $reqSpecIDParamName = "reqspecid";
public static $scopeParamName = "scope";
public static $summaryParamName = "summary";
public static $statusParamName = "status";
public static $stepsParamName = "steps";
public static $testCaseIDParamName = "testcaseid";
public static $testCaseExternalIDParamName = "testcaseexternalid";
public static $testCaseNameParamName = "testcasename";
public static $testCasePathNameParamName = "testcasepathname";
public static $testCasePrefixParamName = "testcaseprefix";
public static $testCaseVersionIDParamName = "testcaseversionid";
public static $testModeParamName = "testmode";
public static $testPlanIDParamName = "testplanid";
public static $testPlanNameParamName = "testplanname";
public static $testProjectIDParamName = "testprojectid";
public static $testProjectNameParamName = "testprojectname";
public static $testSuiteIDParamName = "testsuiteid";
public static $testSuiteNameParamName = "testsuitename";
public static $timeStampParamName = "timestamp";
public static $titleParamName = "title";
public static $urgencyParamName = "urgency";
public static $userEmailParamName = "email";
public static $userFirstNameParamName = "firstname";
public static $userIDParamName = "userid";
public static $userLastNameParamName = "lastname";
public static $userLoginParamName = "login";
public static $userParamName = "user";
public static $userPasswordParamName = "password";
public static $versionNumberParamName = "version";
public static $estimatedExecDurationParamName = "estimatedexecduration";
public static $executionDurationParamName = "execduration";
public static $prefixParamName = "prefix";
public static $testCaseVersionParamName = "tcversion";
public static $itsNameParamName = "itsname";
public static $itsEnabledParamName = "itsenabled";
public static $copyTestersFromBuildParamName = "copytestersfrombuild";
/**
* #@-
*/
/**
* An array containing strings for valid statuses
* Will be initialized using user configuration via config_get()
*/
public $statusCode;
public $codeStatus;
/**
* Constructor sets up the IXR_Server and db connection
*/
public function __construct($callbacks = array()) {
$this->dbObj = new database( DB_TYPE );
$this->dbObj->db->SetFetchMode( ADODB_FETCH_ASSOC );
$this->_connectToDB();
global $g_tlLogger;
$this->tlLogger = &$g_tlLogger;
$this->tlLogger->setDB( $this->dbObj );
// This close the default transaction that is started
// when logger.class.php is included.
$this->tlLogger->endTransaction();
$this->tcaseMgr = new testcase( $this->dbObj );
$this->tprojectMgr = new testproject( $this->dbObj );
$this->tplanMgr = new testplan( $this->dbObj );
$this->tplanMetricsMgr = new tlTestPlanMetrics( $this->dbObj );
$this->reqSpecMgr = new requirement_spec_mgr( $this->dbObj );
$this->reqMgr = new requirement_mgr( $this->dbObj );
$this->userMgr = new tlUser( $this->dbObj );
$this->tprojectMgr->setAuditEventSource( 'API-XMLRPC' );
$this->tables = $this->tcaseMgr->getDBTables();
$resultsCfg = config_get( 'results' );
foreach( $resultsCfg['status_label_for_exec_ui'] as $key => $label ) {
$this->statusCode[$key] = $resultsCfg['status_code'][$key];
}
if(isset( $this->statusCode['not_run'] )) {
unset( $this->statusCode['not_run'] );
}
$this->codeStatus = array_flip( $this->statusCode );
$this->initMethodYellowPages();
$this->methods += $callbacks;
// after changing IXR_Server() constructor to __contructor()
parent::__construct( $this->methods );
}
/**
*/
protected function _setArgs($args, $opt = null) {
// TODO: should escape args
$this->args = $args;
if(isset( $this->args[self::$testProjectNameParamName] ) && ! isset( $this->args[self::$testProjectIDParamName] )) {
$name = trim( $this->args[self::$testProjectNameParamName] );
$projects = $this->tprojectMgr->get_by_name( $name );
if (! is_null( $projects )) {
$info = current( $projects );
$this->args[self::$testProjectIDParamName] = $info['id'];
}
}
}
/**
* Set the BuildID from one place
*
* @param int $buildID
* @access protected
*/
protected function _setBuildID($buildID) {
if(GENERAL_ERROR_CODE != $buildID) {
$this->args[self::$buildIDParamName] = $buildID;
return true;
} else {
$this->errors[] = new IXR_Error( INVALID_BUILDID, INVALID_BUILDID_STR );
return false;
}
}
/**
* Set test case internal ID
*
* @param int $tcaseID
* @access protected
*/
protected function _setTestCaseID($tcaseID) {
$this->args[self::$testCaseIDParamName] = $tcaseID;
}
/**
* Set Build Id to latest build id(if test plan has builds)
*
* @return boolean
* @access protected
*/
protected function _setBuildID2Latest() {
$tplan_id = $this->args[self::$testPlanIDParamName];
$maxbuildid = $this->tplanMgr->get_max_build_id( $tplan_id );
$status_ok =($maxbuildid > 0);
if($status_ok) {
$this->_setBuildID( $maxbuildid );
}
return $status_ok;
}
/**
* connect to the db and set up the db object
*
* @access protected
*
* @internal revisions:
* 20100731 - asimon - BUGID 3644(additional fix for BUGID 2607)
* 20100711 - franciscom - BUGID 2607 - UTF8 settings for MySQL
*/
protected function _connectToDB() {
if(true == $this->testMode) {
$this->dbObj->connect( TEST_DSN, TEST_DB_HOST, TEST_DB_USER, TEST_DB_PASS, TEST_DB_NAME );
} else {
$this->dbObj->connect( DSN, DB_HOST, DB_USER, DB_PASS, DB_NAME );
}
// asimon - BUGID 3644 & 2607 - $charSet was undefined here
$charSet = config_get( 'charset' );
if((DB_TYPE == 'mysql') &&($charSet == 'UTF-8')) {
$this->dbObj->exec_query( "SET CHARACTER SET utf8" );
$this->dbObj->exec_query( "SET collation_connection = 'utf8_general_ci'" );
}
}
/**
* authenticates a user based on the devKey provided
*
* This is the only method that should really be used directly to authenticate
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function authenticate($messagePrefix = '') {
// check that the key was given as part of the args
if(! $this->_isDevKeyPresent()) {
$this->errors[] = new IXR_ERROR( NO_DEV_KEY, $messagePrefix . NO_DEV_KEY_STR );
$this->authenticated = false;
return false;
} else {
$this->devKey = $this->args[self::$devKeyParamName];
}
// make sure the key we have is valid
if(! $this->_isDevKeyValid( $this->devKey )) {
$this->errors[] = new IXR_Error( INVALID_AUTH, $messagePrefix . INVALID_AUTH_STR );
$this->authenticated = false;
return false;
} else {
// Load User
$this->user = tlUser::getByID( $this->dbObj, $this->userID );
$this->authenticated = true;
$this->tlLogger->startTransaction( 'DEFAULT', null, $this->userID );
return true;
}
}
/**
* Check if authenticated user has System Wide Role admin
*
* Useful for services reserved to System Wide Role admin
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkIsSystemWideAdmin($messagePrefix = '') {
$res = ($this->user->globalRole->dbID == TL_ROLES_ADMIN);
if (!$res) {
$this->errors[] = new IXR_Error( MUST_BE_ADMIN, $messagePrefix . MUST_BE_ADMIN_STR );
}
return $res;
}
/**
* checks if a user has requested right on test project, test plan pair.
*
* @param string $rightToCheck
* one of the rights defined in rights table
* @param boolean $checkPublicPrivateAttr
* (optional)
* @param map $context
* (optional)
* keys testprojectid,testplanid(both are also optional)
*
* @return boolean
* @access protected
*
*/
protected function userHasRight($rightToCheck, $checkPublicPrivateAttr = false, $context = null) {
$status_ok = true;
// Site admin has all rights
if ($this->user->globalRole->dbID == TL_ROLES_ADMIN) {
return true;
}
$tprojectid = intval( isset( $context[self::$testProjectIDParamName] ) ? $context[self::$testProjectIDParamName] : 0 );
if($tprojectid == 0 && isset( $this->args[self::$testProjectIDParamName] )) {
$tprojectid = $this->args[self::$testProjectIDParamName];
}
if(isset( $context[self::$testPlanIDParamName] )) {
$tplanid = $context[self::$testPlanIDParamName];
} else {
$tplanid = isset( $this->args[self::$testPlanIDParamName] ) ? $this->args[self::$testPlanIDParamName] : null;
}
$tprojectid = intval( $tprojectid );
$tplanid = ! is_null( $tplanid ) ? intval( $tplanid ) : - 1;
if($tprojectid <= 0 && $tplanid > 0) {
// get test project from test plan
$ox = array(
'output' => 'minimun'
);
$dummy = $this->tplanMgr->get_by_id( $tplanid, $ox );
$tprojectid = intval( $dummy['tproject_id'] );
}
// Contribution by frankfal
// Some APIs only provide TestSuiteID or TestCaseID, look up TestProjectID
if ($tprojectid <= 0 && $tplanid == -1) {
// Try using TestSuiteID to get TestProjectID
$tsuitid = intval( isset( $context[self::$testSuiteIDParamName] ) ? $context[self::$testSuiteIDParamName] : 0 );
if($tsuiteid == 0 && isset( $this->args[self::$testSuiteIDParamName] )) {
$tsuiteid = intval( $this->args[self::$testSuiteIDParamName] );
}
if ($tsuiteid > 0) {
$dummy = $this->tprojectMgr->tree_manager->get_path( $tsuiteid );
$tprojectid = $dummy[0]['parent_id'];
} else {
// Try using TestCaseID to get TestProjectID
$tcaseid = intval( isset( $context[self::$testCaseIDParamName] ) ? $context[self::$testCaseIDParamName] : 0 );
if($tcaseid == 0 && isset( $this->args[self::$testCaseIDParamName] )) {
$tcaseid = intval( $this->args[self::$testCaseIDParamName] );
}
if ($tcaseid > 0) {
$tprojectid = $this->tcaseMgr->get_testproject( $tcaseid );
}
}
}
if(! $this->user->hasRight( $this->dbObj, $rightToCheck, $tprojectid, $tplanid, $checkPublicPrivateAttr )) {
$status_ok = false;
$msg = sprintf( INSUFFICIENT_RIGHTS_STR, $this->user->login, $rightToCheck, $tprojectid, $tplanid );
$this->errors[] = new IXR_Error( INSUFFICIENT_RIGHTS, $msg );
}
if(isset( $context['updaterID'] )) {
$updUser = tlUser::getByID( $this->dbObj, intval( $context['updaterID'] ) );
$sk = $updUser->hasRight( $this->dbObj, $rightToCheck, $tprojectid, $tplanid, $checkPublicPrivateAttr );
if(! $sk) {
$status_ok = false;
$msg = sprintf( UPDATER_INSUFFICIENT_RIGHTS_STR, $updUser->login, $rightToCheck, $tprojectid, $tplanid );
$this->errors[] = new IXR_Error( UPDATER_INSUFFICIENT_RIGHTS, $msg );
}
}
return $status_ok;
}
/**
* Helper method to see if the testcasename provided is valid
*
* This is the only method that should be called directly to check the testcasename
*
* @return boolean
* @access protected
*/
protected function checkTestCaseName() {
$status = true;
if(! $this->_isTestCaseNamePresent()) {
$this->errors[] = new IXR_Error( NO_TESTCASENAME, NO_TESTCASENAME_STR );
$status = false;
} else {
$testCaseName = $this->args[self::$testCaseNameParamName];
if(! is_string( $testCaseName )) {
$this->errors[] = new IXR_Error( TESTCASENAME_NOT_STRING, TESTCASENAME_NOT_STRING_STR );
$status = false;
}
}
return $status;
}
/**
* Helper method to see if the status provided is valid
*
* This is the only method that should be called directly to check the status
*
* @return boolean
* @access protected
*/
protected function checkStatus() {
if(($status = $this->_isStatusPresent())) {
if(!($status = $this->_isStatusValid( $this->args[self::$statusParamName] ))) {
$msg = sprintf( INVALID_STATUS_STR, $this->args[self::$statusParamName] );
$this->errors[] = new IXR_Error( INVALID_STATUS, $msg );
}
} else {
$this->errors[] = new IXR_Error( NO_STATUS, NO_STATUS_STR );
}
return $status;
}
/**
* Helper method to see if the tcid provided is valid
*
* This is the only method that should be called directly to check the tcid
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkTestCaseID($messagePrefix = '') {
$msg = $messagePrefix;
$status_ok = $this->_isTestCaseIDPresent();
if($status_ok) {
$tcaseid = $this->args[self::$testCaseIDParamName];
if(! $this->_isTestCaseIDValid( $tcaseid )) {
$this->errors[] = new IXR_Error( INVALID_TCASEID, $msg . INVALID_TCASEID_STR );
$status_ok = false;
}
} else {
$this->errors[] = new IXR_Error( NO_TCASEID, $msg . NO_TCASEID_STR );
}
return $status_ok;
}
/**
* Helper method to see if the testcaseversionid provided is valid
*
* This is the only method that should be called directly to check the tcversionid
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkTestCaseVersionID($messagePrefix = '') {
$msg = $messagePrefix;
$status_ok = $this->_isTestCaseVersionIDPresent();
if($status_ok) {
$tcaseversionid = $this->args[self::$testCaseVersionIDParamName];
if(! $this->_isTestCaseVersionIDValid( $tcaseversionid, "checkTestCaseVersionID", true )) {
$this->errors[] = new IXR_Error( INVALID_TCASEVERSIONID, sprintf($msg . INVALID_TCASEVERSIONID_STR, $tcaseversionid) );
$status_ok = false;
}
} else {
$this->errors[] = new IXR_Error( NO_TCASEVERSIONID, $msg . NO_TCASEVERSIONID_STR );
}
return $status_ok;
}
/**
* Helper method to see if the tplanid provided is valid
*
* This is the only method that should be called directly to check the tplanid
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkTestPlanID($messagePrefix = '') {
$status = true;
if(! $this->_isTestPlanIDPresent()) {
$msg = $messagePrefix . NO_TPLANID_STR;
$this->errors[] = new IXR_Error( NO_TPLANID, $msg );
$status = false;
} else {
// See if this TPID exists in the db
$tplanid = $this->dbObj->prepare_int( $this->args[self::$testPlanIDParamName] );
$query = "SELECT id FROM {$this->tables['testplans']} WHERE id={$tplanid}";
$result = $this->dbObj->fetchFirstRowSingleColumn( $query, "id" );
if(null == $result) {
$msg = $messagePrefix . sprintf( INVALID_TPLANID_STR, $tplanid );
$this->errors[] = new IXR_Error( INVALID_TPLANID, $msg );
$status = false;
} else {
// tplanid exists and its valid
// Do we need to try to guess build id ?
if($this->checkGuess() &&(! $this->_isBuildIDPresent() && ! $this->_isParamPresent( self::$buildNameParamName, $messagePrefix ))) {
$status = $this->_setBuildID2Latest();
}
}
}
return $status;
}
/**
* Helper method to see if the TestProjectID provided is valid
*
* This is the only method that should be called directly to check the TestProjectID
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkTestProjectID($messagePrefix = '') {
if(!($status = $this->_isTestProjectIDPresent())) {
$this->errors[] = new IXR_Error( NO_TESTPROJECTID, $messagePrefix . NO_TESTPROJECTID_STR );
} else {
// See if this Test Project ID exists in the db
$testprojectid = $this->dbObj->prepare_int( $this->args[self::$testProjectIDParamName] );
$query = "SELECT id FROM {$this->tables['testprojects']} WHERE id={$testprojectid}";
$result = $this->dbObj->fetchFirstRowSingleColumn( $query, "id" );
if(null == $result) {
$msg = $messagePrefix . sprintf( INVALID_TESTPROJECTID_STR, $testprojectid );
$this->errors[] = new IXR_Error( INVALID_TESTPROJECTID, $msg );
$status = false;
}
}
return $status;
}
/**
* Helper method to see if the testproject identity provided is valid
* Identity can be specified in one of these modes:
*
* - internal id(DB)
* - prefix
*
*
* If everything OK, test project internal ID is setted.
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkTestProjectIdentity($messagePrefix = '') {
$status = false;
$fromExternal = false;
$fromInternal = false;
if($this->_isTestProjectIDPresent()) {
$fromInternal = true;
$status = $this->checkTestProjectID( $messagePrefix );
} else if($this->_isParamPresent( self::$prefixParamName, $messagePrefix, true )) {
// Go for the prefix
$fromExternal = true;
$target = $this->dbObj->prepare_string( $this->args[self::$prefixParamName] );
$sql = " SELECT id FROM {$this->tables['testprojects']} WHERE prefix='{$target}' ";
$fieldValue = $this->dbObj->fetchFirstRowSingleColumn( $sql, "id" );
$status =(! is_null( $fieldValue ) &&(intval( $fieldValue ) > 0));
if($status) {
$this->args[self::$testProjectIDParamName] = $fieldValue;
} else {
$status = false;
$msg = $messagePrefix . sprintf( TPROJECT_PREFIX_DOESNOT_EXIST_STR, $target );
$this->errors[] = new IXR_Error( TPROJECT_PREFIX_DOESNOT_EXIST, $msg );
}
} else {
$status = false;
}
return $status;
}
/**
* Helper method to see if the UserID provided is valid
*
* This is the only method that should be called directly to check the UserID
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkUserID($messagePrefix = '') {
if(!($status = $this->_isUserIDPresent())) {
$this->errors[] = new IXR_Error( NO_USERID, $messagePrefix . NO_USERID_STR );
} else {
// See if this user ID exists in the DB
$userid = $this->dbObj->prepare_int( $this->args[self::$userIDParamName] );
$query = "SELECT id FROM {$this->tables['users']} WHERE id={$userid}";
$result = $this->dbObj->fetchFirstRowSingleColumn( $query, "id" );
if(null == $result) {
$msg = $messagePrefix . sprintf( INVALID_USERID_STR, $userid );
$this->errors[] = new IXR_Error( INVALID_USERID, $msg );
$status = false;
}
}
return $status;
}
/**
* Helper method to see if the user identity provided is valid
* Identity can be specified in one of these modes:
*
* - internal id(DB)
* - login
*
*
* If everything OK, user internal ID is setted.
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkUserIdentity($messagePrefix = '') {
$status = false;
$fromExternal = false;
$fromInternal = false;
if($this->_isUserIDPresent()) {
$fromInternal = true;
$status = $this->checkUserID( $messagePrefix );
} else if($this->_isParamPresent( self::$userLoginParamName, $messagePrefix, true )) {
// Go from the login
$fromExternal = true;
$target = $this->dbObj->prepare_string( $this->args[self::$userLoginParamName] );
$sql = " SELECT id FROM {$this->tables['users']} WHERE login='{$target}' ";
$fieldValue = $this->dbObj->fetchFirstRowSingleColumn( $sql, "id" );
$status =(! is_null( $fieldValue ) &&(intval( $fieldValue ) > 0));
if($status) {
$this->args[self::$UserIDParamName] = $fieldValue;
} else {
$status = false;
$msg = $messagePrefix . sprintf( USER_LOGIN_DOESNOT_EXIST_STR, $target );
$this->errors[] = new IXR_Error( USER_LOGIN_DOESNOT_EXIST, $msg );
}
} else {
$status = false;
}
return $status;
}
/**
* Helper method to see if the roleID provided is valid
*
* This is the only method that should be called directly to check the roleID
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkRoleID($messagePrefix = '') {
if(!($status = $this->_isRoleIDPresent())) {
$this->errors[] = new IXR_Error( NO_ROLEID, $messagePrefix . NO_ROLEID_STR );
} else {
// See if this role ID exists in the DB
$roleid = $this->dbObj->prepare_int( $this->args[self::$roleIDParamName] );
$query = "SELECT id FROM {$this->tables['roles']} WHERE id={$roleid}";
$result = $this->dbObj->fetchFirstRowSingleColumn( $query, "id" );
if(null == $result) {
$msg = $messagePrefix . sprintf( INVALID_ROLEID_STR, $roleid );
$this->errors[] = new IXR_Error( INVALID_ROLEID, $msg );
$status = false;
}
}
return $status;
}
/**
* Helper method to see if the role identity provided is valid
* Identity can be specified in one of these modes:
*
* - internal id(DB)
* - description
*
*
* If everything OK, role internal ID is setted.
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkRoleIdentity($messagePrefix = '') {
$status = false;
$fromExternal = false;
$fromInternal = false;
if($this->_isRoleIDPresent()) {
$fromInternal = true;
$status = $this->checkRoleID( $messagePrefix );
} else if($this->_isParamPresent( self::$roleNameParamName, $messagePrefix, true )) {
// Go from the name
$fromExternal = true;
$target = $this->dbObj->prepare_string( $this->args[self::$roleNameParamName] );
$sql = " SELECT id FROM {$this->tables['roles']} WHERE description='{$target}' ";
$fieldValue = $this->dbObj->fetchFirstRowSingleColumn( $sql, "id" );
$status =(! is_null( $fieldValue ) && (intval( $fieldValue ) > 0));
if($status) {
$this->args[self::$roleIDParamName] = $fieldValue;
} else {
$msg = $messagePrefix . sprintf( ROLE_NAME_DOESNOT_EXIST_STR, $target );
$this->errors[] = new IXR_Error( ROLE_NAME_DOESNOT_EXIST, $msg );
}
} else {
$status = false;
}
return $status;
}
/**
* Helper method to see if the TestSuiteID provided is valid
*
* This is the only method that should be called directly to check the TestSuiteID
*
* @param string $messagePrefix
* used to be prepended to error message
*
* @return boolean
* @access protected
*/
protected function checkTestSuiteID($messagePrefix = '') {
if(!($status = $this->_isTestSuiteIDPresent())) {
$this->errors[] = new IXR_Error( NO_TESTSUITEID, $messagePrefix . NO_TESTSUITEID_STR );
} else {
// See if this Test Suite ID exists in the db
$tsuiteMgr = new testsuite( $this->dbObj );
$node_info = $tsuiteMgr->get_by_id( $this->args[self::$testSuiteIDParamName] );
if(!($status = ! is_null( $node_info ))) {
$msg = $messagePrefix . sprintf( INVALID_TESTSUITEID_STR, $this->args[self::$testSuiteIDParamName] );
$this->errors[] = new IXR_Error( INVALID_TESTSUITEID, $msg );
}
}
return $status;
}
/**
* Helper method to see if the guess is set
*
* This is the only method that should be called directly to check the guess param
*
* Guessing is set to true by default
*
* @return boolean
* @access protected
*/
protected function checkGuess() {
// if guess is set return its value otherwise return true to guess by default
return($this->_isGuessPresent() ? $this->args[self::$guessParamName] : self::BUILD_GUESS_DEFAULT_MODE);
}
/**
* Helper method to see if the buildID provided is valid for testplan
*
* if build id has not been provided on call, we can use build name if has been provided.
*
* This is the only method that should be called directly to check the buildID
*
* @return boolean
* @access protected
*
* @internal revision
*/
protected function checkBuildID($msg_prefix) {
$tplan_id = $this->args[self::$testPlanIDParamName];
$status = true;
$try_again = false;
// First thing is to know is test plan has any build
$buildQty = $this->tplanMgr->getNumberOfBuilds( $tplan_id );
if($buildQty == 0) {
$status = false;
$tplan_info = $this->tplanMgr->get_by_id( $tplan_id );
$msg = $msg_prefix . sprintf( TPLAN_HAS_NO_BUILDS_STR, $tplan_info['name'], $tplan_info['id'] );
$this->errors[] = new IXR_Error( TPLAN_HAS_NO_BUILDS, $msg );
}
if($status) {
if(! $this->_isBuildIDPresent()) {
$try_again = true;
if($this->_isBuildNamePresent()) {
$try_again = false;
$bname = trim( $this->args[self::$buildNameParamName] );
$buildInfo = $this->tplanMgr->get_build_by_name( $tplan_id, $bname );
if(is_null( $buildInfo )) {
$msg = $msg_prefix . sprintf( BUILDNAME_DOES_NOT_EXIST_STR, $bname );
$this->errors[] = new IXR_Error( BUILDNAME_DOES_NOT_EXIST, $msg );
$status = false;
} else {
$this->args[self::$buildIDParamName] = $buildInfo['id'];
}
}
}
if($try_again) {
// this means we aren't supposed to guess the buildid
if(false == $this->checkGuess()) {
$this->errors[] = new IXR_Error( NO_BUILDID, NO_BUILDID_STR );
$status = false;
} else {
$setBuildResult = $this->_setBuildID2Latest();
if(false == $setBuildResult) {
$this->errors[] = new IXR_Error( NO_BUILD_FOR_TPLANID, NO_BUILD_FOR_TPLANID_STR );
$status = false;
}
}
}
if($status) {
$buildID = $this->dbObj->prepare_int( $this->args[self::$buildIDParamName] );
$buildInfo = $this->tplanMgr->get_build_by_id( $tplan_id, $buildID );
if(is_null( $buildInfo )) {
$tplan_info = $this->tplanMgr->get_by_id( $tplan_id );
$msg = sprintf( BAD_BUILD_FOR_TPLAN_STR, $buildID, $tplan_info['name'], $tplan_id );
$this->errors[] = new IXR_Error( BAD_BUILD_FOR_TPLAN, $msg );
$status = false;
}
}
}
return $status;
}
/**
* Helper method to see if a param is present
*
* @param string $pname
* parameter name
* @param string $messagePrefix
* used to be prepended to error message
* @param boolean $setError
* default false
* true: add predefined error code to $this->error[]
*
* @return boolean
* @access protected
*
*
*/