1111use CDash \Model \Coverage ;
1212use CDash \Model \CoverageFile ;
1313use CDash \Model \CoverageFileLog ;
14- use CDash \Model \CoverageSummary ;
1514use CDash \Model \Project ;
1615use Illuminate \Http \JsonResponse ;
1716use Illuminate \Http \RedirectResponse ;
1817use Illuminate \Support \Facades \Auth ;
1918use Illuminate \Support \Facades \DB ;
20- use Illuminate \Support \Facades \Gate ;
2119use Illuminate \View \View ;
2220
2321require_once 'include/filterdataFunctions.php ' ;
@@ -34,161 +32,6 @@ public function compareCoverage(): View|RedirectResponse
3432 return $ this ->angular_view ('compareCoverage ' );
3533 }
3634
37- /**
38- * TODO: (williamjallen) this function contains legacy XSL templating and should be converted
39- * to a proper Blade template with Laravel-based DB queries eventually. This contents
40- * this function are originally from manageCoverage.php and have been copied (almost) as-is.
41- */
42- public function manageCoverage (): View |RedirectResponse
43- {
44- $ userid = Auth::id ();
45- // Checks
46- if (!isset ($ userid ) || !is_numeric ($ userid )) {
47- return $ this ->view ('cdash ' )
48- ->with ('xsl ' , true )
49- ->with ('xsl_content ' , 'Not a valid userid! ' );
50- }
51-
52- $ xml = begin_XML_for_XSLT ();
53- $ xml .= '<menutitle>CDash</menutitle> ' ;
54- $ xml .= '<menusubtitle>Coverage</menusubtitle> ' ;
55-
56- @$ projectid = $ _GET ['projectid ' ];
57- if ($ projectid != null ) {
58- $ projectid = intval ($ projectid );
59- }
60-
61- $ Project = new Project ();
62-
63- $ buildid = 0 ;
64- if (isset ($ _GET ['buildid ' ])) {
65- $ buildid = intval ($ _GET ['buildid ' ]);
66- }
67-
68- // If the projectid is not set and there is only one project we go directly to the page
69- // TODO: (williamjallen) Should this be one project in all of CDash, or one project we can see?
70- if (!isset ($ projectid ) && EloquentProject::count () === 1 ) {
71- $ projectid = EloquentProject::all ()->firstOrFail ()->id ;
72- }
73- $ projectid = intval ($ projectid );
74-
75- /** @var User $User */
76- $ User = Auth::user ();
77- $ Project ->Id = $ projectid ;
78- if ($ projectid > 0 && !Gate::allows ('edit-project ' , $ Project )) {
79- return $ this ->view ('cdash ' )
80- ->with ('xsl ' , true )
81- ->with ('xsl_content ' , "You don't have the permissions to access this page " );
82- }
83-
84- $ sql = 'SELECT id,name FROM project ' ;
85- $ params = [];
86- if ($ User ->admin ) {
87- $ sql .= ' WHERE id IN (SELECT projectid AS id FROM user2project WHERE userid=? AND role>0) ' ;
88- $ params [] = intval ($ userid );
89- }
90-
91- $ db = Database::getInstance ();
92- $ project = $ db ->executePrepared ($ sql , $ params );
93- foreach ($ project as $ project_array ) {
94- $ xml .= '<availableproject> ' ;
95- $ xml .= add_XML_value ('id ' , $ project_array ['id ' ]);
96- $ xml .= add_XML_value ('name ' , $ project_array ['name ' ]);
97- if ($ project_array ['id ' ] == $ projectid ) {
98- $ xml .= add_XML_value ('selected ' , '1 ' );
99- }
100- $ xml .= '</availableproject> ' ;
101- }
102-
103- // Display the current builds who have coverage for the past 7 days
104- $ currentUTCTime = gmdate (FMT_DATETIME );
105- $ beginUTCTime = gmdate (FMT_DATETIME , time () - 3600 * 7 * 24 ); // 7 days
106-
107- // Change the priority of selected files, assuming that the bulk replacement takes priority.
108- if (isset ($ _POST ['changePrioritySelected ' ])) {
109- foreach ($ _POST ['selectionFiles ' ] ?? [] as $ key => $ value ) {
110- $ this ->setFilePriority ($ Project ->Id , htmlspecialchars ($ value ), intval ($ _POST ['prioritySelectedSelection ' ]));
111- }
112- } elseif (isset ($ _POST ['prioritySelection ' ])) {
113- $ this ->setFilePriority ($ Project ->Id , $ _POST ['fullpath ' ] ?? '' , intval ($ _POST ['prioritySelection ' ] ?? -1 ));
114- }
115-
116- /* We start generating the XML here */
117-
118- // Find the recent builds for this project
119- if ($ projectid > 0 ) {
120- $ xml .= '<project> ' ;
121- $ xml .= add_XML_value ('id ' , $ Project ->Id );
122- $ xml .= add_XML_value ('name ' , $ Project ->GetName ());
123- $ xml .= add_XML_value ('name_encoded ' , urlencode ($ Project ->GetName ()));
124-
125- if ($ buildid > 0 ) {
126- $ xml .= add_XML_value ('buildid ' , $ buildid );
127- }
128-
129- $ CoverageSummary = new CoverageSummary ();
130-
131- $ buildids = $ CoverageSummary ->GetBuilds ($ Project ->Id , $ beginUTCTime , $ currentUTCTime );
132- rsort ($ buildids );
133- foreach ($ buildids as $ buildId ) {
134- $ Build = new Build ();
135- $ Build ->Id = $ buildId ;
136- $ Build ->FillFromId ($ Build ->Id );
137- $ xml .= '<build> ' ;
138- $ xml .= add_XML_value ('id ' , $ buildId );
139- $ xml .= add_XML_value ('name ' , $ Build ->GetSite ()->name . '- ' . $ Build ->GetName () . ' [ ' . gmdate (FMT_DATETIME , strtotime ($ Build ->StartTime )) . '] ' );
140- if ($ buildid > 0 && $ buildId == $ buildid ) {
141- $ xml .= add_XML_value ('selected ' , 1 );
142- }
143- $ xml .= '</build> ' ;
144- }
145-
146- // For now take the first one
147- if ($ buildid > 0 ) {
148- // Find the files associated with the build
149- $ Coverage = new Coverage ();
150- $ Coverage ->BuildId = $ buildid ;
151- $ fileIds = $ Coverage ->GetFiles ();
152- $ row = '0 ' ;
153- sort ($ fileIds );
154- foreach ($ fileIds as $ fileid ) {
155- $ CoverageFile = new CoverageFile ();
156- $ CoverageFile ->Id = $ fileid ;
157- $ xml .= '<file> ' ;
158-
159- $ file_path = $ CoverageFile ->GetPath ();
160-
161- $ xml .= add_XML_value ('fullpath ' , $ file_path );
162- $ xml .= add_XML_value ('id ' , $ CoverageFile ->Id );
163- $ xml .= add_XML_value ('fileid ' , $ fileid );
164-
165- $ row = $ row == 0 ? 1 : 0 ;
166-
167- $ xml .= add_XML_value ('row ' , $ row );
168-
169- $ priority = (int ) (DB ::select ('
170- SELECT priority
171- FROM coveragefilepriority
172- WHERE fullpath=? AND projectid=?
173- ' , [$ file_path , $ Project ->Id ])[0 ]->priority ?? 0 );
174-
175- if ($ priority > 0 ) {
176- $ xml .= add_XML_value ('priority ' , $ priority );
177- }
178-
179- $ xml .= '</file> ' ;
180- }
181- }
182- $ xml .= '</project> ' ;
183- }
184- $ xml .= '</cdash> ' ;
185-
186- return $ this ->view ('cdash ' , 'Manage Coverage ' )
187- ->with ('xsl ' , true )
188- ->with ('xsl_content ' , generate_XSLT ($ xml , base_path () . '/app/cdash/public/manageCoverage ' , true ))
189- ->with ('project ' , $ Project );
190- }
191-
19235 private static function get_cdash_dashboard_xml_by_name (string $ projectname , $ date ): string
19336 {
19437 $ projectid = get_project_id ($ projectname );
@@ -612,28 +455,6 @@ public function viewCoverage(): View|RedirectResponse
612455 ->with ('xsl_content ' , generate_XSLT ($ xml , 'viewCoverage ' , true ));
613456 }
614457
615- private function setFilePriority (int $ projectid , string $ file_path , int $ priority ): void
616- {
617- $ count = (int ) (DB ::select ('
618- SELECT count(*) AS c
619- FROM coveragefilepriority
620- WHERE FullPath=?
621- ' , [$ file_path ])[0 ]->c ?? 0 );
622-
623- if ($ count === 0 ) {
624- DB ::insert ('
625- INSERT INTO coveragefilepriority (projectid, priority, fullpath)
626- VALUES (?, ?, ?)
627- ' , [$ projectid , $ priority , $ file_path ]);
628- } else {
629- DB ::update ('
630- UPDATE coveragefilepriority
631- SET priority=?
632- WHERE fullpath=? AND projectid=?
633- ' , [$ priority , $ file_path , $ projectid ]);
634- }
635- }
636-
637458 public function viewCoverageFile (): View
638459 {
639460 $ this ->setBuildById (intval ($ _GET ['buildid ' ] ?? 0 ));
@@ -791,9 +612,6 @@ public function ajaxGetViewCoverage(): JsonResponse
791612 case 5 :
792613 $ sortby = 'branches ' ;
793614 break ;
794- case 6 :
795- $ sortby = 'priority ' ;
796- break ;
797615 }
798616 } else {
799617 switch (intval ($ _GET ['iSortCol_0 ' ])) {
@@ -809,9 +627,6 @@ public function ajaxGetViewCoverage(): JsonResponse
809627 case 3 :
810628 $ sortby = 'lines ' ;
811629 break ;
812- case 5 :
813- $ sortby = 'priority ' ;
814- break ;
815630 }
816631 }
817632 }
@@ -851,23 +666,18 @@ public function ajaxGetViewCoverage(): JsonResponse
851666 c.branchestested,
852667 c.branchesuntested,
853668 c.functionstested,
854- c.functionsuntested,
855- cfp.priority
669+ c.functionsuntested
856670 FROM
857671 coverage AS c,
858672 coveragefile AS cf
859- LEFT JOIN coveragefilepriority AS cfp ON (
860- cfp.fullpath=cf.fullpath
861- AND projectid=?
862- )
863673 WHERE
864674 c.buildid=?
865675 AND cf.id=c.fileid
866676 AND c.covered=1
867677 $ filter_sql
868678 $ SQLsearchTerm
869679 $ limit_sql
870- " , array_merge ([$ this ->project -> Id , $ this -> build ->Id ], $ SQLsearchTermParams , $ limit_sql_params ));
680+ " , array_merge ([$ this ->build ->Id ], $ SQLsearchTermParams , $ limit_sql_params ));
871681
872682 // Add the coverage type
873683 $ status = (int ) ($ _GET ['status ' ] ?? -1 );
@@ -930,9 +740,6 @@ public function ajaxGetViewCoverage(): JsonResponse
930740 $ coveragetype = 'gcov ' ;
931741 }
932742
933- // Add the priority
934- $ covfile ['priority ' ] = $ coveragefile_array ['priority ' ];
935-
936743 if ($ covfile ['coveragemetric ' ] != 1.0 || $ status !== -1 ) {
937744 $ covfile_array [] = $ covfile ;
938745 }
@@ -946,7 +753,6 @@ public function ajaxGetViewCoverage(): JsonResponse
946753 $ fullpath = dirname ($ fullpath );
947754 if (!isset ($ directory_array [$ fullpath ])) {
948755 $ directory_array [$ fullpath ] = [];
949- $ directory_array [$ fullpath ]['priority ' ] = 0 ;
950756 $ directory_array [$ fullpath ]['directory ' ] = 1 ;
951757 $ directory_array [$ fullpath ]['covered ' ] = 1 ;
952758 $ directory_array [$ fullpath ]['fileid ' ] = 0 ;
@@ -1004,20 +810,15 @@ public function ajaxGetViewCoverage(): JsonResponse
1004810 $ coveragefile = $ db ->executePrepared ("
1005811 SELECT
1006812 cf.fullpath,
1007- cfp.priority
1008813 FROM
1009814 coverage AS c,
1010815 coveragefile AS cf
1011- LEFT JOIN coveragefilepriority AS cfp ON (
1012- cfp.fullpath=cf.fullpath
1013- AND projectid=?
1014- )
1015816 WHERE
1016817 c.buildid=?
1017818 AND cf.id=c.fileid
1018819 AND c.covered=0
1019820 $ SQLsearchTerm
1020- " , [$ this ->project -> Id , $ this -> build ->Id ]);
821+ " , [$ this ->build ->Id ]);
1021822
1022823 foreach ($ coveragefile as $ coveragefile_array ) {
1023824 $ covfile = [];
@@ -1034,8 +835,6 @@ public function ajaxGetViewCoverage(): JsonResponse
1034835 $ covfile ['percentcoverage ' ] = 0 ;
1035836 $ covfile ['coveragemetric ' ] = 0 ;
1036837
1037- $ covfile ['priority ' ] = $ coveragefile_array ['priority ' ];
1038-
1039838 $ covfile_array [] = $ covfile ;
1040839 }
1041840 }
@@ -1425,28 +1224,6 @@ public function ajaxGetViewCoverage(): JsonResponse
14251224 $ row [] = $ nextcolumn2 ;
14261225 }
14271226
1428- // Fifth column (Priority)
1429- // Get the priority
1430- $ priority = 'NA ' ;
1431- switch ($ covfile ['priority ' ]) {
1432- case 0 :
1433- $ priority = '<div>None</div> ' ;
1434- break ;
1435- case 1 :
1436- $ priority = '<div>Low</div> ' ;
1437- break ;
1438- case 2 :
1439- $ priority = '<div class="warning">Medium</div> ' ;
1440- break ;
1441- case 3 :
1442- $ priority = '<div class="error">High</div> ' ;
1443- break ;
1444- case 4 :
1445- $ priority = '<div class="error">Urgent</div> ' ;
1446- break ;
1447- }
1448- $ row [] = $ priority ;
1449-
14501227 // Sixth colum (Authors)
14511228 if ($ userid > 0 ) {
14521229 $ author = '' ;
@@ -1564,14 +1341,6 @@ private function sort_branches($a, $b): int
15641341 return $ a ['branchesuntested ' ] > $ b ['branchesuntested ' ] ? 1 : -1 ;
15651342 }
15661343
1567- private function sort_priority ($ a , $ b ): int
1568- {
1569- if ($ a ['priority ' ] == $ b ['priority ' ]) {
1570- return 0 ;
1571- }
1572- return $ a ['priority ' ] > $ b ['priority ' ] ? 1 : -1 ;
1573- }
1574-
15751344 public function ajaxShowCoverageGraph (): View
15761345 {
15771346 $ buildid = $ _GET ['buildid ' ];
0 commit comments